note 37138 deleted from function.oci-error by sixd

From: Date: Sat, 14 Nov 2009 02:23:56 +0000
Subject: note 37138 deleted from function.oci-error by sixd
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162897@lists.php.net to get a copy of this message
Note Submitter: vi at sh dot nu Reason: 0 ---- 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

« previous php.notes (#162897) next »