PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject » Bug #4968

count() doesn't work after setFetchMode(DB_FETCHMODE_ASSOC)

Details

Request #4968count() doesn't work after setFetchMode(DB_FETCHMODE_ASSOC)
Submitted2005-08-02 10:35 UTC
Fromalbert at jool dot nl
StatusClosed
PackageDB_DataObject
PHP Version4.3.11
OSall
Roadmaps(Not assigned)

Comments

[2005-08-02 10:35 UTC] albert at jool dot nl

Description:
------------
Tested with DB_DataObject 1.7.15.

Test script:
---------------
Sample code doesn't work but gives an idea of reproducing it:

$person = DB_DataObject::factory('person');
$db =& $person->getDatabaseConnection();
$db->setFetchMode(DB_FETCHMODE_ASSOC);
$total = $person->count();

echo $total;

---

the bug is on line 1502-1503 of DataObject.php:
$l = $result->fetchRow();
return $l[0];

With DB_FETCHMODE_ASSOC, $l[0] doesn't contain anything, because the count result is stored in $l['DATAOBJECT_NUM']

Expected result:
----------------
$total should be the number of person rows in the db

Actual result:
--------------
'' or null is returned.

[2005-08-02 11:59 UTC] albert at jool dot nl

simple solution, no risk:

change line 1502 from
$l = $result->fetchRow();
to
$l = $result->fetchRow(DB_FETCHMODE_ORDERED);

[2005-08-02 12:03 UTC] albert at jool dot nl

line 1502 from DataObject.php of course :)

and yes, I didn't expect that the count function would be influenced by changing fetch methods, especially when you're using the $db object for other queries.