php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #25917 odbc_error() sometimes returns a bad string
Submitted: 2003-10-20 03:49 UTC Modified: 2004-09-16 15:18 UTC
Votes:9
Avg. Score:4.9 ± 0.3
Reproduced:6 of 7 (85.7%)
Same Version:5 (83.3%)
Same OS:4 (66.7%)
From: thorsten at rinne dot info Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4CVS, 5CVS OS: Windows2000
Private report: No CVE-ID: None
 [2003-10-20 03:49 UTC] thorsten at rinne dot info
Description:
------------
We use IBM DB2 databases on our Windows2000 systems. The bug occured then writing a database class.

The odbc_error() function returns sometimes bad strings with special characters. If a real error occurs, the function returns the correct six-digit ODBC state. After that, the error code will not be removed from memory and the error code will be returned on every query although it is correct.

Note:
var_dump(odbc_error()) returns sometimes bad strings with special characters, sometimes nothing.


Reproduce code:
---------------
    function myquery($query) {
        $result = odbc_exec($conn, $query);
        if (odbc_error($conn)) {
            print "SQLQuery: ".$query;
            print "ErrorNum: ".odbc_error($conn));
            print "ErrorMsg: ".odbc_errormsg($conn));
            }
        return $result;
        }

Expected result:
----------------
The expected result should be empty when no error occured and the six-digit ODBC state when an error occured. After every correct new query, the result should be empty.

Actual result:
--------------
Here are some results, the queries are correct:

SQLQuery: SELECT * FROM SYSTEM
ErrorNum: 8??P?
ErrorMsg: ?x??

or

SQLQuery: SELECT * FROM SYSTEM2
ErrorNum: ?WPW
ErrorMsg: 

or 

SQLQuery: SELECT * FROM SYSTEM
ErrorNum: 
ErrorMsg: 



Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-22 08:32 UTC] thorsten at rinne dot info
This bug can also reproduced with PHP 4.3.4RC1 and 4.3.4RC2. This happens with INSERTS, UPDATEs and DELETEs, too.
 [2003-10-22 19:49 UTC] kalowsky@php.net
can you please turn on the logging option in your client, and post the relavent portions to this bug?  Under windows it's in the ODBC Administrator.
 [2003-10-27 02:28 UTC] thorsten at rinne dot info
Here's my log:

SQLQuery: SELECT * FROM TABLE
ErrorNum: 4???
ErrorMsg: ?

Here's the odbc log:

[ Process: 924, Thread: 1084 ]
[ Date & Time:          27/10/2003 08.23.23.000015 ]
[ Product:              QDB2/NT DB2 v8.1.3.132 ]
[ Level Identifier:     02040106 ]
[ CLI Driver Version:   08.01.0000 ]
[ Informational Tokens: "DB2 v8.1.3.132","s030728","WR21324","Fixpack 3" ]

[0000000924 0000001084] [27/10/2003 08.23.36.934791] SQLExecDirectW( hStmt=1:1, pszSqlStr="SELECT * FROM TABLE" - X"530045004C004500430054002000490044005F004D00410049004C0052004F004F004D002C0020004400450053004300520049005000540049004F004E002C0020005300450052005600450052004E0041004D0045002000460052004F004D0020004D00410049004C0052004F004F004D00", cbSqlStr=-3 )
[0000000924 0000001084] [27/10/2003 08.23.36.935123]

[0000000924 0000001084] [27/10/2003 08.23.36.935863] SQLExecDirectW( )
[0000000924 0000001084] [27/10/2003 08.23.36.935972]     <--- SQL_SUCCESS
 [2003-10-31 09:35 UTC] kalowsky@php.net
This is probably a documentation bug (and therefore a 
misunderstanding on your code) more than a PHP ODBC 
code bug.

What you're seeing happening is an abuse of the 
odbc_error system really.  The odbc_error values are 
only populated when an internal error is detected (i.e. 
SQLExecDirect() fails).   The catch is they only over-
write the values that had been in there previously.  As 
such the each connections last error is never really 
free'd, so you'll constantly get a copy of the last 
seen error.  Does that make sense?

In any case you should be checking the return code for 
the function you're calling rather than just 
odbc_error().

Moving to a documentation bug.
 [2003-11-03 02:29 UTC] thorsten at rinne dot info
Your explanation makes sense. Why does odbc_error sometimes return bad strings with special characters? Is this a bug in PHP or from the ODBC driver?
 [2004-09-16 15:18 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

odbc_error, odbc_errormsg: "This function returns meaningful value only if last odbc query failed (i.e. odbc_exec() returned false)."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Aug 18 18:01:28 2024 UTC