oracle 获取 oci_execute() 错误的错误消息 (PHP)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10129619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:43:48  来源:igfitidea点击:

Getting Error Message For oci_execute() Error (PHP)

oracleoracle10g

提问by Bad Programmer

I would like to get the specific error message if a query fails in Oracle 10g. For MySQL, PHP has the mysql_error() function that can return details about why a query failed. I check the php.net manual for the oci_execute() function, but from what I see it only returns false on fail.

如果在 Oracle 10g 中查询失败,我想获得特定的错误消息。对于 MySQL,PHP 具有 mysql_error() 函数,可以返回有关查询失败原因的详细信息。我检查了 oci_execute() 函数的 php.net 手册,但从我看来,它只在失败时返回 false。

I tried using oc_error(), but I am not getting anything from it.

我尝试使用 oc_error(),但我没有从中得到任何信息。

Here is a code sample:

这是一个代码示例:

    $err = array();
    $e = 0;

    //Cycle through all files and insert new records into database
    for($f=0; $f<sizeof($files); $f++)
    {
        $invoice_number = $files[$f]['invoice_number'];
        $sold_to = $files[$f]['sold_to'];
        $date = $files[$f]['date'];

        $sql = "insert into invoice (dealer_id, invoice_number, invoice_date) 
                values ('$sold_to', '$invoice_number', '$date')";

        $stid = oci_parse($conn, $sql);
        $result = oci_execute($stid);

        //If query fails
        if(!$result)
        {
            $err[$e] = oci_error();
            $e++;
        }
    } 

    print_r($err);

Response for print_r($err):

对 print_r($err) 的响应:

Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => ) 

回答by Eggi

Have you tried to pass $stid to oci_error?

您是否尝试将 $stid 传递给 oci_error?

$err[$e] = oci_error($stid);

回答by DanielKM

The oci_error()function takes an argument that specifies the context of your error. Passing it no argument will only work for certain kinds of connection errors. What you want to do is pass the parsed statement resource, like so:

oci_error()函数采用一个参数来指定错误的上下文。不传递任何参数仅适用于某些类型的连接错误。您要做的是传递解析后的语句资源,如下所示:

$err = oci_error($stid);

(Note also that the return value from oci_erroris an array, so I assigned the entire output to your $errarray variable)

(另请注意,来自的返回值oci_error是一个数组,因此我将整个输出分配给了您的$err数组变量)