php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30876 odbc_fetch_row($rs,0) does not reset dataset.
Submitted: 2004-11-24 02:26 UTC Modified: 2005-01-18 16:39 UTC
From: rphp at ryanjameson dot com Assigned:
Status: Not a bug Package: ODBC related
PHP Version: 5.0.2 OS: windows 2000
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rphp at ryanjameson dot com
New email:
PHP Version: OS:

 

 [2004-11-24 02:26 UTC] rphp at ryanjameson dot com
Description:
------------
Since upgrading to 5.0 I've found that looping through a recordset ($rs) via odbc_fetch_row and then attempting to reuse the recordset by calling odbc_fetch_row($rs,0) seems to put me at the first record of the recordset versus giving me a "reset" recordset. The result is a subsequent odbc_fetch_row then puts me at the second item in the record set which is not how it behaved in previous versions. 

In previous versions calling odbc_fetch_row($rs,0) followed by odbc_fetch_row($rs) would leave you on the first row since the odbc_fetch_row($rs,0) had in effect reset the recordset. This ability is mentioned in the user contributed notes for this function.

I have a rather large and intracate library partially built around the ability to "reset" recordsets. I have been unable to find another way to do this. Since installing PHP 5.0 all results that relied on this are missing the first row. :-\

Reproduce code:
---------------
create a simple odbc record set ($rs) by selecting from any table then...

odbc_fetch_row($rs); //moves the pointer
//in past this would reset the pointer
odbc_fetch_row($rs,0); 
$cnt = 0;
while (fetch($rs))
  $cnt++;
echo "$cnt is one less than the actual result count because it started on the second row!";

Expected result:
----------------
I expect $cnt to equal the number of rows in the result set because odbc_fetch_row($rs,0) should reset the set, not move the pointer to the first row.

Actual result:
--------------
$cnt is one less than the result count.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-18 16:39 UTC] tony2001@php.net
The docs say:
"To step through the result more than once, you can call odbc_fetch_row() with row_number 1, and then continue doing odbc_fetch_row() without row_number to review the result. If a driver doesn't support fetching rows by number, the row_number parameter is ignored."
You should use 1 instead of 0.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC