|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-05-22 09:09 UTC] atampone at attechcomputer dot com
In previous versions of PHP you could reset the pointer on ODBC resutls using odbc_fetch_row($results,0). This no longer works! I can find no other way to reset ODBC results. If you check for results and then try to loop through the results, you will loose the 1st row! - Anthony PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 28 11:00:02 2025 UTC |
Here is pysudocode for an example script that will casue this error. $c=odbc_connect("some source", "uname", "pass" ); $res = odbc_exec($c,"some SQL statement"); if (!odbc_fetch_row($res)) // check if there are results { // do something } else { odbc_fetch_row($res,0); // reset results <<-- this is what doesn't work while (odbc_fetch_row($res)) { // loop through results } } what happens in this expample is that the pointer on teh $res resource is advanced when the odbc_fetch_row() function is called in the if statement. It is then advanced when called again in the while statement and the first row gets lost. This happens because the odbc_fetch_row($res,0) does not move the pointer back to 0. In versions of PHP prior to 4.2.1 odbc_fetch_row($res,0) worked properly. Only after 4.2.1 has it become broken. I had to write twice as much code to get arround this and I run into this quite often. I had to rewrite quite a few functions becasue of this bug. - Anthony"nothing has changed to the odbc_fetch_row function in the last... 3 or 4 releases" Ok but the script below work fine i php 4.1.2, but dies in 4.2.0 and 4.2.1 function odbc_record_count($sql_id, $CurrRow = 0) { $NumRecords = 0; odbc_fetch_row($sql_id,0); while (odbc_fetch_row($sql_id)) { $NumRecords++; } if( !odbc_fetch_row($sql_id, $CurrRow)) die("odbc_record_count - odbc_fetch_row($CurrRow) failed"); return $NumRecords; } btw odbc_num_rows still dont work properly