2

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

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

这是一个代码示例:

    $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);

print_r($err) 的响应:

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

2 回答 2

7

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

$err[$e] = oci_error($stid);
于 2012-04-15T13:20:03.677 回答
3

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:

$err = oci_error($stid);

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

于 2013-10-30T16:26:15.820 回答