Detect position of Error in SQL stmt

admin

Administrator
Staff member
If I execute the following SQL in SQLPLUS:

select JOB from MyTable where JIB = 'xyz';

and JIB is supposed to be JOB, SQLPLUS highlights JIB in the statement letting me know that an error occurred at that position. If I were to run this same statement in a PHP script, how do I capture the exact position of the error in the SQL statement (ie. "Error occured at line 31." would be nice to show the client when running a PHP script with the above problem). Here's a sample of a code snipet that we would like to enhance with error position info:

$stmt = @OCIParse($dbc, $sql);
if ($stmt)
{
if (@OCIExecute($stmt,OCI_DEFAULT))
{
return $stmt;
}
else
{
//Send the client an error notification.
LogError("CMN_DB", "DbExecute: Failed SQL: \"$sql\"","", false);
return false;
}
}
else
{
//Send the client an error notification.
LogError("CMN_DB", "DbExecute: Error parsing SQL: \"$sql\"","", false);
return false;
}
 
Back
Top