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