note 36359 deleted from function.ocierror by sixd

From: Date: Mon, 05 Oct 2009 02:07:27 +0000
Subject: note 36359 deleted from function.ocierror by sixd
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161329@lists.php.net to get a copy of this message
Note Submitter: cjbj at hotmail dot com ---- 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"; ?>

« previous php.notes (#161329) next »