php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
Description:
------------
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:
http://pecl4win.php.net/download.php/ext/5_1/5.1.2/php_ibm_db2.dll
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

Thanks


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>';
var_dump($value);
var_dump($value2);


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) ""


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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 http://us2.php.net/manual/en/function.db2-result.php):

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():
http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/r0000604.htm
does not indicate that you cannot query the same column twice.

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC