php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #25773 OCIError documentation incorrect about "last error"
Submitted: 2003-10-07 05:50 UTC Modified: 2004-05-24 09:19 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: cjbj at hotmail dot com Assigned: tony2001 (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Windows 2000
Private report: No CVE-ID: None
 [2003-10-07 05:50 UTC] 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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-07 14:23 UTC] goba@php.net
Yes it will definitely help if you write up something to cut and paste. Thanks for contributing, Goba.
 [2004-01-23 00:15 UTC] cjbj at hotmail dot com
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>";
}
 [2004-05-22 11:37 UTC] nlopess@php.net
Can you take a look to this, please? Thanks!
 [2004-05-24 09:19 UTC] tony2001@php.net
Fixed, thanks for pointing to this bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 04:01:30 2024 UTC