ID: 25773
User updated by: cjbj at hotmail dot com
Reported By: cjbj at hotmail dot com
Status: Open
Bug Type: Documentation problem
Operating System: Windows 2000
-PHP Version: 4.3.3
+PHP Version: Irrelevant
New Comment:
This is far from the last word on the topic, but enhances the existing
content with the basics. The text I am suggesting follows. I've
removed "global" from the prototype. No other oci8 manual page
mentions what this is.
----------
(PHP 3>= 3.0.7, PHP 4)
ocierror -- Return the last Oracle error
array ocierror ([resource conn|stmt])
Description
ocierror() returns the last Oracle error. If an error had not
occurred, ocierror() returns FALSE.
For most errors, the parameter is the most appropriate resource
handle. For connection errors with OCILogon, OCINLogon or OCIPLogon,
do not pass a parameter.
ocierror() returns the error as an associative array. This array
contains:
"code" (int) Oracle error number
"message" (string) Oracle error message
"offset" (int) Character position of the error in the statement
(if any)
"sqltext" (string) Statement (if any) that cause the error
The "offset" and "sqltext" entries are available from PHP 4.3 onwards.
Example 1. Displaying the Oracle error message after a connection
error
$conn = @OCILogon("scott", "tiger", "mydb");
if (!$conn) {
$e = OCIError(); // For OCILogon errors pass no handle
echo htmlentities($e['message']);
}
Example 2. Displaying the Oracle error message after a parsing error
$stmt = @OCIParse($conn, "select ' from dual"); // note mismatched
quote
if (!$stmt) {
$e = OCIError($conn); // For OCIParse errors pass the connection
handle
echo htmlentities($e['message']);
}
Example 3. Displaying the Oracle error message and problematic
statement after an execution error
$r = @OCIExecute($stmt);
if (!$r) {
$e = OCIError($stmt); // For OCIExecute errors pass the statement
handle
echo htmlentities($e['message']);
echo "<pre>";
echo htmlentities($e['sqltext']);
printf("\n%".($e['offset']+1)."s", "^");
echo "</pre>";
}
Previous Comments:
------------------------------------------------------------------------
[2003-10-07 14:23:56] [EMAIL PROTECTED]
Yes it will definitely help if you write up something to cut and paste.
Thanks for contributing, Goba.
------------------------------------------------------------------------
[2003-10-07 05:50:42] cjbj at hotmail dot com
Description:
------------
This is similar to http://bugs.php.net/bug.php?id=9510, which was
closed two years ago saying the docs need to be updated. However the
docs have still not been updated. Also there are no real useful
user-supplied notes in the manual entry despite them being referred to
in http://bugs.php.net/bug.php?id=8993
How do we get the OCIError documentation updated? Will
it help if I write something to cut-and-paste?
Re-description of the problem:
The OCIError documentation
http://www.php.net/manual/en/function.ocierror.php says that if no
parameter is given, then the most recent error is displayed:
"If the optional stmt|conn|global is not provided, the last
error encountered is returned"
I am not seeing this with OCIParse or OCIExecute. I am seeing
OCIError return false. This is consistent with the comment in
http://bugs.php.net/bug.php?id=9510 :
"the documentation needs to be updated - ocierror always
stores the error in the most appropiate (parent-)handle. "
Reproduce code:
---------------
<?php
// Display OCI error
function PrintOCIError($t, $err)
{
echo "<pre>$t: ".$err['message']."</pre>\n";
}
echo "<p>Connecting . . . </p>";
$con = @OCILogon("scott", "tiger", "T920");
if (!$con) {
PrintOCIError(@OCIError());
}
// Deliberate syntax error: missing a single quote
$stid = @OCIParse($con, "select 'x from dual");
if (!$stid) {
$e = OCIError();
PrintOCIError("First error ", $e);
// The correct error is displayed when $con is passed to OCIError
$e = OCIError($con);
PrintOCIError("Second error ", $e);
}
?>
Expected result:
----------------
According to the documentation the testcase should give:
Connecting . . .
First error : ORA-01756: quoted string not properly terminated
Second error : ORA-01756: quoted string not properly terminated
Actual result:
--------------
The testcase gives:
Connecting . . .
First error :
Second error : ORA-01756: quoted string not properly terminated
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=25773&edit=1