|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-03-24 08:14 UTC] powerblade at mail dot dk
Description:
------------
When executing a statement it goes as this:
oci_parse() - Validates the SQL statement. However this always returns true so it can't be trusted.
oci_execute() - Executes the query. If anything goes wrong, it simply outputs it to the screen. If you put a @ infront to avoid the warning and then use oci_error() to get the error, you don't get the error string it outputs to the screen.
Reproduce code:
---------------
$query = 'XYZZYX'; /* Invalid SQL string */
$stmt = oci_parse($this->connection, $query);
$aError = oci_error();
if($aError)
{
throw new DatabaseException("[".$aError['code']."] Can't parse query. ".$aError['message']);
}
$return = oci_execute($stmt);
if($return === FALSE)
{
$aError = @oci_error();
throw new DatabaseException("[".$aError['code']."] Can't execute query. ".$aError['message']);
}
Expected result:
----------------
Uncaught exception with the string:
[error code] Can't parse query. [error msg]
or
[error code] Can't execute query. [error msg]
Actual result:
--------------
Uncaught exception with the string:
[] Can't execute query []
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 16:00:01 2025 UTC |
Your code works fine for me. It returns: --- Warning: oci_execute() [function.oci-execute.html]: OCIStmtExecute: ORA-00900: invalid SQL statement in /www/index.php on line 27 Fatal error: Uncaught exception 'DatabaseException' with message '[] Can't execute query. ' in /www/index.php:31 Stack trace: #0 {main} thrown in /www/index.php on line 31 --- >oci_parse() - Validates the SQL statement. However this always returns true so it can't be trusted. no, this is not true. it does return false, if something went wrong. >...and then use oci_error() to get the error, you don't get the error string it outputs to the screen. Please, re-check it twice. This is false too. And, please, provide more information about your system. What version of Oracle & Oracle client do you use?Not only the documentation. See my #2. ----- 2) Where is the oracle error message in the exception? I need that info for debugging. ----- If you look in the exception you get: ----------------------- Fatal error: Uncaught exception 'DatabaseException' with message '[] Can't execute query. ' in /www/index.php:31 Stack trace: #0 {main} thrown in /www/index.php on line 31 -------------------------------- The oracle error message and code is not included in the exception. Even though in the code it threw the exception with the following statement: throw new DatabaseException("[".$aError['code']."] Can't execute query. ".$aError['message']); The only way to grab the oracle error is to set up a custom error handler. You can't use oci_error() to retrieve it.you need to pass $stmt to oci_error(); in this case. so, your code will look like this: <? /* ... */ $query = 'XYZZYX'; /* Invalid SQL string */ $stmt = oci_parse($this->connection, $query); $return = @oci_execute($stmt); if($return === FALSE) { $aError = oci_error($stmt); //$stmt here throw new DatabaseException("[".$aError['code']."] Can't execute query. ".$aError['message']); } ?> Requalifying as documentation problem and assigning to myself..