note 37138 added to function.ocierror
| From: | vi at sh dot nu | Date: | Tue, 04 Nov 2003 18:29:13 +0000 |
| Subject: | note 37138 added to function.ocierror | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-59899@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
----
Manual Page -- http://www.php.net/manual/en/function.ocierror.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37138
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37138&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37138&report=yes
Search -- http://master.php.net/manage/user-notes.php