[nycphp-talk] PHP 5 guru: help fix simple PEAR DB problem
Dan Cech
dcech at phpwerx.net
Sun Feb 1 23:58:00 EST 2004
Daniel Convissor wrote:
> Hi Folks:
>
> I just uploaded the latest release of PEAR DB, 1.6.0RC3.
>
> Can someone who's more familliar with PHP 5 than I please help fix the
> following problem?
>
> The DB_common::getAssoc() method works fine in PHP 4 but is producing
> really weird results under PHP 5. If you're wondering, PHP 5 is a windows
> snapshot from today.
Hmm, I don't use PEAR DB myself, but looking at the relevant lines from
common.php:
if ($fetchmode == DB_FETCHMODE_ASSOC) {
while (is_array($row =
$res->fetchRow(DB_FETCHMODE_ASSOC))) {
reset($row);
$key = current($row);
unset($row[key($row)]);
if ($group) {
$results[$key][] = $row;
} else {
$results[$key] = $row;
}
}
} elseif ($fetchmode == DB_FETCHMODE_OBJECT) {
while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
$arr = get_object_vars($row);
$key = current($arr);
if ($group) {
$results[$key][] = $row;
} else {
$results[$key] = $row;
}
}
} else {
It appears the code is not resetting the internal pointer of the array
returned by get_object_vars ($row), which may be causing the odd
behaviour....
I would suggest changing both $key = current($row); lines in the above
code to $key = reset($row); and removing the existing call in the
FETCHMODE_ASSOC section.
Just my thoughts....
Dan
More information about the talk
mailing list