PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB_DataObject » Bug #2260

Documentation error with fetch

Details

Submitted2004-08-31 16:19 UTC
Fromcorey at eyewantmedia dot com
StatusBogus
PackageDB_DataObject
PHP Version5.0.1
OSWinXP Pro
Roadmaps(Not assigned)

Comments

[2004-08-31 16:19 UTC] corey at eyewantmedia dot com

Description:
------------
If you use fetch the way the documentation says to, you always skip the first row.

Reproduce code:
---------------
while ($myObject->fetch() {
//do something.
} //skips first record

if ($myObject->N > 0) {
do {
//do something
} while ($myObject->fetch())
} //is the way you have to do this

or

$test = ($myobject->N > 0) > true : false;
while ($test) {
//do something
$test = $myObject->fetch();
}

Expected result:
----------------
You cycle through all of the records in the deal

Actual result:
--------------
You always miss the first record.

[2004-08-31 18:02 UTC] test at test dot com

The original report was about this page:
http://pear.php.net/manual/en/package.database.db-dataobject.db-dataobject.fetch.php

But I have something new to report. I submitted this issue while I was trying

do {
//operate directly on stuff here
} while($myObject->fetch());

and it always skipped the first row. However, when I switched to doing

do {
$someArray[] = $myObject->toArray();
} while($myObject->fetch());

it added a row in the beginning, so this is some wacky kind of bug. If you are adding things to an array for later, you do

while($myObject->fetch()) {
$someArray[] = $myObject->toArray();
}

otherwise, you have to

do {
//operate directly on stuff here
} while($myObject->fetch());

Could this have something to do with whether or not an autofetch is triggered?