|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57129 Second call to db2_result() for same column returns empty string
Submitted: 2006-07-07 17:53 UTC Modified: 2006-07-10 17:12 UTC
From: jtray at us dot ibm dot com Assigned:
Status: Closed Package: ibm_db2 (PECL)
PHP Version: 5.1.2 OS: Windows XP Pro SP2
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.
Block user comment
Status: Assign to:
Bug Type:
From: jtray at us dot ibm dot com
New email:
PHP Version: OS:


 [2006-07-07 17:53 UTC] jtray at us dot ibm dot com
Although the first call to db2_result() returns the correct value, an immediate second call to db2_result() with the same parameters returns an empty string.  My interpretation of the documentation is that db2_result() does not change the result-set state, and may be called any number of times.

ibm_db2 DLL from here:
I think it is version 1.2.3

DB2 version info:
DB2 administration tools level:
Product identifier           SQL08023
Level identifier             03040106
Level                        DB2 v8.1.10.812
Build level                  s050811
PTF                          WR21362


Reproduce code:
$db = db2_pconnect(...);
$pstmt = db2_prepare($db, 'select * from bug');
$success = db2_execute($pstmt);
$row = db2_fetch_row($pstmt);
$value = db2_result($pstmt, 'FOO');
print 'first value = "' . $value . '"</br>';
$value2 = db2_result($pstmt, 'FOO');
print 'second value = "' . $value2 . '"<br>';

Expected result:
first value = "hi mom"
second value = "hi mom"
string(6) "hi mom"
string(6) "hi mom"

Actual result:
first value = "hi mom"
second value = ""
string(6) "hi mom"
string(0) ""


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-10 14:58 UTC] kfbombar at us dot ibm dot com
The ibm_db2 extension defines db2_result as the following (from

Use db2_result() to return the value of a specified column in the current row of a result set. You must call db2_fetch_row() before calling db2_result() to set the location of the result set pointer.

So you must call db2_fetch_row directly before you call db2_result.  This is why the db2_result is returning an empty string in the second case.
 [2006-07-10 17:12 UTC] jtray at us dot ibm dot com
As my code example indicates, I did call db2_fetch_row() before calling db2_result():

$row = db2_fetch_row($pstmt);
$value = db2_result($pstmt, 'FOO');
print 'first value = "' . $value . '"</br>';
$value2 = db2_result($pstmt, 'FOO');
print 'second value = "' . $value2 . '"<br>';

Certainly you can call db2_result() more than once per call to db2_fetch_row(), because that's how you get multiple column values:

$row = db2_fetch_row($pstmt);
$value = db2_result($pstmt, 'FOO');
$value2 = db2_result($pstmt, 'BAR');

I don't see any reason why the caller cannot ask about the same column twice, and this restriction is not documented.  Also, if it is illegal to ask twice about the same column, db2_result() should return an error the second time.

The underlying DB2 call SQLGetData():
does not indicate that you cannot query the same column twice.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Dec 06 20:03:41 2022 UTC