|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-04-24 04:32 UTC] ltning at anduin dot net
Running on IBM DB2 UDB version 7.1 for Linux, PHP compiled with --with-ibm-db2 configure option.
Given the following table definition:
CREATE TABLE foo (bar1 INTEGER, bar2 LONG VARCHAR)
Connecting to the database:
$conn=odbc_connect("TESTDB", "username", "password");
Inserting data:
$rc=odbc_exec($conn, "INSERT INTO foo VALUES (1, 'This is some really long data..')");
And then running the following script:
for($i=1;$i<3;$i++) {
$rc=odbc_fetch_row($q, 0);
$result=odbc_result($q, $i);
echo "Data:".$result;
}
The first iteration returns the data from bar1 correctly.
The second iteration will give the following error on the line containing the ODBC_result() call:
Warning: SQL error: [IBM][CLI Driver] CLI0115E Invalid cursor state.
SQLSTATE=24000, SQL state 24000 in SQLGetData in /home/ltning/webmail2/functions/test.php on line 10
I have found that I do NOT get this error if I do not use the ODBC_fetch_row() function prior to the second iteration (moving that line out of the loop). My theory is that the DB2 engine handles ODBC_fetch_row() & ODBC_result() calls differently when LONG VARCHAR fields are involved than otherwise, and PHP does not know how to handle this.
I need to use the ODBC_fetch_row() on every iteration because I'm creating custom database functions, and there should be nothing directly "wrong" with that. I.e. this _should_ work..
If I can provide any other information, please tell me.. ;)
Best regards,
Eirik Overby
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 20:00:01 2025 UTC |
I also got similar issue when I tryed use odbc_fetch_row($rs, 0) on DB2 database. if ($num_records < 0) { // If odbc_num_rows returns -1 value then we can calculate the record count using while loop. $num_records=0; while(odbc_fetch_row($rs)) { $num_records++; } odbc_fetch_row($rs, 0); //This will point firsr record of the record set } after executing this code when i try execute odbc_result($rs,1); it gives blank value where as value is present in database.It works fine with other databases.