2

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] => ) 

2 Answers 2

7

Have you tried to pass $stid to oci_error?

$err[$e] = oci_error($stid);
Sign up to request clarification or add additional context in comments.

Comments

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.