php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #27315 ODBC Not returning all error messages
Submitted: 2004-02-18 16:08 UTC Modified: 2022-04-07 19:19 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: bergy at us dot ibm dot com Assigned: ilutov (profile)
Status: Closed Package: ODBC related
PHP Version: 4.3.4 OS: Red Hat 8.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bergy at us dot ibm dot com
New email:
PHP Version: OS:

 

 [2004-02-18 16:08 UTC] bergy at us dot ibm dot com
Description:
------------
When accessing a DB2 database (either DB2 version 7 or 8) via ODBC (i.e., PHP compiled without the --with-db2 flag), every odbc_exec call that generates an error, returns the error message:

function.odbc-exec.html</a>]: SQL error: [unixODBC][IBM][CLI Driver] CLI0005W  Option value changed. SQLSTATE=01S02, SQL state 01S02 in SQLExecDirect in ...

Notice that the message (returned by odbc_errormsg), and the corresponding error number (returned by odbc_error) point to the warning, even though an error occured.  We have confirmed that an error has occured, but it is not due to the option value changing.

This appears to be a duplicate of bug number 15141, which is from 21 Jan 2002 and was closed "No Feedback".

I have examined the ODBC source code, and see that function odbc_sql_error has comments in it that indicated that it was orgionally designed to retrieve all the errors assoicated with an ODBC call.  The loop is commented out, and the comments indicate that some ODBC device drivers would cause an endless loop.  These comments appear in the latest snapshot.

Since I can't control the options that are generating the "option value changed" warning, I'd really like a solution where I can see the real errors.  I'm not familiar enough with the PHP and ODBC soure to be competent in suggesting a solution, but it would appear to me that returning multiple error messages while guarding against an endless loop would be appropriate.  Perhaps a simple counter to return no more than 5 messages (which I would think would be enough, given that no one else seems to notice that it won't return more than 1) would work.

Reproduce code:
---------------
<?php
if ( $cid = odbc_connect("coredev", "xxxxx", "xxxxx") ) {
  if ( $rid = @odbc_exec($cid, "select count(*) from c_sensor") ) {
    if ( odbc_fetch_into($rid, $result) ) {
      echo "No Error Occured, result: ", var_dump($result), "\n";
    } else {
      echo "Error on odbc_fetch_into:\n";
      echo "  ", odbc_errormsg($cid), "\n";
    }
  } else {
    echo "Error on odbc_exec:\n";
    echo "  ", odbc_errormsg($cid), "\n";
  }
} else {
  echo "Error trying to connect to database\n";
}
?>

Expected result:
----------------
In the sample code above, the sql statement is in error, because the table referenced doesn't exist.  The output should be:

Error on odbc_exec:
  [unixODBC][IBM][CLI Driver] SQL0204N  "BERGY.C_SENSOR" is an undefined name.  SQLSTATE=42704


Actual result:
--------------
Error on odbc_exec:
  [unixODBC][IBM][CLI Driver] CLI0005W  Option value changed. SQLSTATE=01S02


Patches

xqxmjbea (last revision 2020-04-18 03:51 UTC by sample at email dot tst)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-30 18:55 UTC] cmb@php.net
-Package: Feature/Change Request +Package: ODBC related
 [2020-04-18 03:51 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: xqxmjbea
Revision:   1587181917
URL:        https://bugs.php.net/patch-display.php?bug=27315&patch=xqxmjbea&revision=1587181917
 [2022-04-07 19:19 UTC] ilutov@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ilutov
 [2022-04-07 19:19 UTC] ilutov@php.net
Lots of time has passed since this issue was created. If this is still relevant, please create an issue on GitHub.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 16:01:28 2024 UTC