Getting Error Message For oci_execute() Error (PHP)

余生颓废 提交于 2019-12-05 05:47:18

问题


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.

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

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):

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

回答1:


Have you tried to pass $stid to oci_error?

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



回答2:


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)



来源:https://stackoverflow.com/questions/10129619/getting-error-message-for-oci-execute-error-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!