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: 2016-12-30 18:55 UTC
From: bergy at us dot ibm dot com Assigned:
Status: Open Package: ODBC related
PHP Version: 4.3.4 OS: Red Hat 8.0
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

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
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 13:01:52 2019 UTC