Bug #17357 Updated: odbc_fetch_row is broke in 4.2.1
| From: | kalowsky@php.net | Date: | Mon, 24 Jun 2002 21:36:04 +0000 |
| Subject: | Bug #17357 Updated: odbc_fetch_row is broke in 4.2.1 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-11977@lists.php.net to get a copy of this message | ||
ID: 17357
Updated by: kalowsky@php.net
Reported By: atampone@attechcomputer.com
-Status: Feedback
+Status: Closed
Bug Type: ODBC related
Operating System: Windows 2000 Advanced Server
PHP Version: 4.2.1
New Comment:
This works for me in 4.2.1 and a recent pull from CVS.
Previous Comments:
------------------------------------------------------------------------
[2002-06-06 09:18:44] kalowsky@php.net
Sorry that last message is more for gory@alaphsoft-bg.com
------------------------------------------------------------------------
[2002-06-06 09:16:44] kalowsky@php.net
1) Please realize that register_globals is turned off in PHP 4.2.x
2) Can you please provide a full sample script to reproduce the
problem? The snippit you've shown doesn't really help as it doesn't
show the full process for the code being used.
------------------------------------------------------------------------
[2002-06-06 03:59:17] gory@alphasoft-bg.com
"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
------------------------------------------------------------------------
[2002-06-04 12:15:16] atampone@attechcomputer.com
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
------------------------------------------------------------------------
[2002-05-31 18:39:17] davidr@pophost.com
If any of the other 12 respondents can produce code to demostrate, it
will help.. mine is buried in an complex applications, and I will have
to develop a demo scenario. I can tell you everthing worked fine on
PHP 4.1.X, and broke when we upgraded to 4.2.X Only after we traced it
did we find that the direct row specification on the ODBC_FETCH_ROW
command was being ignored, and several other functions that would use
similiar direct row addresses. Perhaps it was a compile error... I
can't say. But it will take me a while to put together a set of demo
functions and database schema...
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/17357
--
Edit this bug report at http://bugs.php.net/?id=17357&edit=1