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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 - 4 = ?
Subscribe to this entry?

 
 [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 26 05:01:30 2024 UTC