【问题标题】:"CLI has stopped working" when trying to select all from an Oracle Database using JQuery?尝试使用 JQuery 从 Oracle 数据库中全选时出现“CLI 已停止工作”?
【发布时间】:2016-07-16 01:29:14
【问题描述】:

我正在尝试使用 JavaScript 和 Jquery 来搜索数据库。我已经建立了一个通用的 query.php 文件,这样我就可以传入数据库并查询并让它返回一个数组。出于某种原因,当我尝试使用 * 全选时,我的 PHP 服务器崩溃:

我正在使用 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 行。

【问题讨论】:

  • php 错误日志显示什么?
  • 可能是内存限制问题。尝试在您的 php 中将 memory_limit 设置为 0。
  • @steven - 我试过了。它没有解决问题...
  • @codeHeart - 据我了解,内置 PHP 服务器默认没有错误日志。我在 php.ini 文件中添加了 log_errors = On 和 error_log = /tmp/php_error.log,但崩溃时没有创建日志。

标签: javascript php jquery oracle


【解决方案1】:

我通过将 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 对象数组的函数进行了重大更改,但它确实有效。不过,我不会将此答案标记为正确,因为我非常想知道为什么我的原始代码不起作用...

【讨论】:

    猜你喜欢
    • 2015-08-21
    • 2016-10-30
    • 2010-12-12
    • 2015-10-08
    • 2020-10-09
    • 2012-05-26
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多