note 36359 added to function.ocierror
| From: | cjbj at hotmail dot com | Date: | Tue, 07 Oct 2003 10:18:09 +0000 |
| Subject: | note 36359 added to function.ocierror | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57959@lists.php.net to get a copy of this message | ||
The documentation says "If the optional stmt|conn|global is not
provided, the last error encountered is returned". This is not true
and has been noted in bug http://bugs.php.net/bug.php?id=9510 which
says "ocierror always stores the error in the most appropiate
(parent-)handle.". Also see bug http://bugs.php.net/bug.php?id=25773
Here are three examples of what to pass to OCIError to retrieve an
Oracle error.
<?php
//
// These examples are independent, not cumulative. Make only one
// change at a time and then run the script.
//
// Example 1: Login errors:
// Change the database to something invalid. The Oracle
// error should be:
// ORA-12154: TNS:could not resolve service name
//
// Example 2: Parsing errors:
// Once you've corrected the username, password and
// database for your site and connected OK, the script
// should give the Oracle error:
// ORA-01756: quoted string not properly terminated
//
// Example 3: Execution errors:
// Change the SQL statement adding a single quote to make
// 'missingquote into 'missingquote'
// The Oracle error should be:
// ORA-00923: FROM keyword not found where expected
$username = "scott";
$password = "tiger";
$database = "MYDB";
$stmt = "select no_such_column 'missingquote from dual";
// Display OCI error
function PrintOCIError($err)
{
echo "<pre>".$err['message']."</pre>\n";
die();
}
$con = @OCILogon($username, $password, $database);
if (!$con) {
$e = OCIError(); // For OCILogon errors pass no parameter
PrintOCIError($e);
}
echo "Connected OK\n";
$stid = @OCIParse($con, $stmt);
if (!$stid) {
$e = OCIError($con); // For OCIParse errors pass the connection
PrintOCIError($e);
}
echo "Parsed OK\n";
$r = @OCIExecute($stid);
if (!$r) {
$e = OCIError($stid); // For OCIExecute errors pass the statement
PrintOCIError($e);
}
echo "Executed OK\n";
?>
----
Manual Page -- http://www.php.net/manual/en/function.ocierror.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36359
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36359&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36359&report=yes
Search -- http://master.php.net/manage/user-notes.php