php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11437 PEAR: DB_common::getAssoc doesn't work correctly with DB_FETCHMODE_ASSOC
Submitted: 2001-06-12 11:04 UTC Modified: 2001-06-14 17:01 UTC
From: marcel at anacker dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.0.5 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marcel at anacker dot com
New email:
PHP Version: OS:

 

 [2001-06-12 11:04 UTC] marcel at anacker dot com
a snippet from DB_common::getAssoc (PEAR/php/DB/common.php):

if ($cols > 2 || $force_array) {
    // return array values
    // XXX this part can be optimized
    while (($row = $this->fetchRow($res, DB_FETCHMODE_ORDERED))
            && !DB::isError($row)) {
        reset($row);
        // we copy the row of data into a new array
        // to get indices running from 0 again
        $results[$row[0]] = array_slice($row, 1);
    }
} else {
    // return scalar values
    while (($row = $this->fetchRow($res)) && !DB::isError($row)) {
        $results[$row[0]] = $row[1];
    }
}

In the if branch fetchRow is called with "DB_FETCHMODE_ORDERED" to ensure the result is indexed by numbers, in the else branch it isn't. I have set the default fetchmode to DB_FETCHMODE_ASSOC and so this function (called with a query with 2 columns) won't work for me unless I call "$DB->setFetchmode(DB_FETCHMODE_ORDERED)" before.
Conclusion: "$this->fetchRow($res))" should be changed to "$this->fetchRow($res,DB_FETCHMODE_ORDERED))"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-14 17:01 UTC] sniper@php.net
This bug system is for reporting bugs in PHP the language,
not anything that has done using it.

Report these bugs to ssb@php.net


 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Aug 19 10:05:45 2022 UTC