javascript - 尝试使用 JQuery 从 Oracle 数据库中选择全部内容时出现 "CLI has stopped working"?

标签 javascript php jquery oracle

我正在尝试使用 JavaScript 和 Jquery 来搜索数据库。我已经设置了一个通用的 query.php 文件,以便我可以传入数据库并查询并让它返回一个数组。由于某种原因,当我尝试使用 * 选择所有内容时,我的 PHP 服务器崩溃了:

enter image description here

我正在使用 PHP 7.0.2 的内置服务器。我正在尝试从 Oracle 数据库检索信息。

以下是帖子声明:

$.post(DB1.filename, 
        {sid: DB1.sid, 
        username: DB1.username, 
        password: DB1.password,
        host: DB1.host,
        port: DB1.port,
        sql: query}, 

        function(res){
            if(res == -1){
                res = errorCode(DATABASE_CONNECTION_ERROR);
            } else {
                var a = parseObject(res);
                var t = parseTable(a);
                elements[TABLE].element.innerHTML = t;
            }
            log(FILE_NAME, "RETRIEVED query ");
        }
    );

这是 query.php:

<?php   
    /* This script will connect to a database and search the given SQL string.
        If the connection cannot be established, it will return -1. Otherwise, it will return a JSON array.
    */

    //Parameters
    $sql = $_POST["sql"];

    //Database Information
    $user = $_POST["username"];
    $pass = $_POST["password"];
    $host = $_POST["host"];
    $port = $_POST["port"];
    $sid = $_POST["sid"];

    $connection = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = " . $host .")(PORT = " . $port . ")) (CONNECT_DATA = (SID = " . $sid . ")))";

    //Establish connection
    $conn = oci_connect($user, $pass, $connection);

    //Check connection
    if(!$conn){
        echo -1;
    } else {        
        //Query for the given SQL statement
        $stRows = oci_parse($conn, $sql);
        oci_execute($stRows);

        oci_fetch_all($stRows, $res); //This is where the everything actually crashes
        echo json_encode($res);

        //Close the connection
        oci_close($conn);
    } 
?>

因此,如果我将查询设置为:

query = "select TABLE_NAME from ALL_TABLES";

一切都很好。具有单列的表格将被打印到屏幕上。

但是,如果我运行:

query = "select * from ALL_TABLES";

我收到上面的错误。

无论我尝试连接到哪个表,都会发生这种情况。我的凭据是正确的,并且我也尝试过不同的凭据。有什么想法为什么会发生这种情况吗?

--更新--

我尝试对列名称进行硬编码。在崩溃之前我最多可以选择 8 列。共有 152 行。

最佳答案

我通过将 oci_fetch_all 替换为 oci_fetch_array 来避免该错误,如下所示:

    <?php   

    ...

    } else {        
        //Query for the given SQL statement
        $stRows = oci_parse($conn, $sql);
        oci_execute($stRows);

        $res = array();
        while($row = oci_fetch_array($stRows, OCI_NUM)){
            $res[] = $row;
        }
        echo json_encode($res);

        //Close the connection
        oci_close($conn);
    } 
?>

这意味着对用于解码 JSON 对象数组的函数进行了重大更改,但它确实有效。不过,我不会将此答案标记为正确,因为我非常想知道为什么我的原始代码不起作用......

关于javascript - 尝试使用 JQuery 从 Oracle 数据库中选择全部内容时出现 "CLI has stopped working"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36268264/

相关文章:

javascript - 如何使用ajax jquery将串行输出从arduino发送到文本框

php - stmt 执行数组并获取

javascript - 提交ajax请求时,如何暂时 "put the original request on hold"直到满足条件?

javascript - 为同一页面的两个部分打印 css

javascript - 如何在angular2中的选择更改事件中获取值

javascript - 在 Drupal 7 中使用 JQuery

javascript - ES6 与 React,无法 setState - 'Cannot read property ' setState' of undefined'?

php - 如何在网站上设置表格?

php - 我可以存储散列的电话号码并将其未散列发送到电子邮件吗?

javascript - 表单提交处理程序未被调用