note 37138 modified in function.ocierror by sixd

From: Date: Mon, 05 Oct 2009 02:08:21 +0000
Subject: note 37138 modified in function.ocierror by sixd
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161330@lists.php.net to get a copy of this message
Here's an example of how to get the offset from an Oracle statement that errored: <? $conn = OCILogon ("user", "password", "database"); $statement = OCIParse ($conn, "select foo, bar from t1 where id = 1"); OCIExecute ($statement, OCI_DEFAULT); $error = OCIError ($statement); if ($error["offset"]) { $sqltext = substr ($error["sqltext"], 0, $error["offset"]) . '*' . substr ($error["sqltext"], $error["offset"]); echo $sqltext; } ?> Presuming the column "foo" doesn't exist in the table "t1", the above code will produce the following: PHP Warning: OCIStmtExecute: ORA-00904: "FOO": invalid identifier in test.php on line 7 select *foo, bar from table where id = 1 Note the asterisk next to the word "foo". This example may seem overly simple, and the error location obvious, but when you have an enormous query, you'll quickly find this functionality very useful. Daniel Ceregatti --was-- Here's an example of how to get the offset from an Oracle statement that errored: <? $conn = OCILogon ("user", "password", "database"); $statement = OCIParse ($conn, "select foo, bar from t1 where id = 1"); OCIExecute ($statement, OCI_DEFAULT); $error = OCIError ($statement); if ($error["offset"]) { $sqltext = substr ($error["sqltext"], 0, $error["offset"]) . '*' . substr ($error["sqltext"], $error["offset"]); echo $sqltext; } ?> Presuming the column "foo" doesn't exist in the table "t1", the above code will produce the following: PHP Warning: OCIStmtExecute: ORA-00904: "FOO": invalid identifier in test.php on line 7 select *foo, bar from table where id = 1 Note the asterisk next to the word "foo". This example may seem overly simple, and the error location obvious, but when you have an enormous query, you'll quickly find this functionality very useful. Daniel Ceregatti http://php.net/manual/en/function.ocierror.php

« previous php.notes (#161330) next »