|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25126 DB::getAssoc() does not use default fetch mode
Submitted: 2003-08-18 05:42 UTC Modified: 2004-04-19 18:37 UTC
From: sjaensch at gmx dot net Assigned: cox (profile)
Status: Closed Package: PEAR related
PHP Version: 4.3.2 OS: Linux
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.
Block user comment
Status: Assign to:
Bug Type:
From: sjaensch at gmx dot net
New email:
PHP Version: OS:


 [2003-08-18 05:42 UTC] sjaensch at gmx dot net
DB::getAssoc() always returns results in DB_FETCHMODE_ORDERED, regardless of the mode set with DB:setFetchMode(). I manually have to call getAssoc($query, FALSE, array(), DB_FETCHMODE_ASSOC) to get column names as indexes. This is not consistent and not documented.

Contrary to the documentation in, the default value for fetchmode is DB_FETCHMODE_ORDERED, as verified in DB/common.php shipped with PHP 4.3.2 (DB 1.1.3) and DB/common.php from DB 1.4.0.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-18 06:22 UTC]
Here is a patch that should fix the issues.

I need feedbacks...

Index: DB/common.php
RCS file: /repository/pear/DB/DB/common.php,v
retrieving revision 1.22
diff -u -u -r1.22 common.php
--- DB/common.php       22 Jul 2003 21:54:16 -0000      1.22
+++ DB/common.php       18 Aug 2003 11:20:54 -0000
@@ -1034,7 +1034,7 @@

     function &getAssoc($query, $force_array = false, $params = array(),
-                       $fetchmode = DB_FETCHMODE_ORDERED, $group = false)
+                       $fetchmode = 'default', $group = false)
         settype($params, "array");
         if (sizeof($params) > 0) {
@@ -1049,6 +1049,9 @@
         } else {
             $res = $this->query($query);
+        if ($fetchmode == 'default') {
+            $fetchmode = $this->fetchmode;
+        }

         if (DB::isError($res)) {
             return $res;

Note: I also have a patch that fixes the oci8 problem #25067
 [2003-08-18 06:40 UTC]
Tomas is on vacation. He will take care of it when he returns.
 [2003-08-28 09:31 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

 [2004-04-19 17:42 UTC] Hubert dot Christiaen at pandora dot be
This problem is not solved. I had code using the setFetchMode(DB_FETCHMODE_ASSOC) in a previous version (2001, $Id: DB.php,v 2001/11/13 01:26:39 
$Id: mysql.php,v 2001/11/13 01:26:42 ) and it worked correctly. Now in the version shipped with SuSE Linux 9.0 (version from 6/2004:
$Id: common.php,v 1.21 2003/06/20 20:41:30 cox Exp $
$Id: mysql.php,v 1.19 2003/06/21 16:45:26 cox Exp $
it does not work correctly. 
Putting some tracing in mysql.php I found that $this->fetchmode == 2 (which is correct) but that $fetchmode == 1 (which is the default DB_FETCHMODE_ORDERED). So it seems that setFetchMode works correctly but that the new value is not passed to the method at execution time.
 [2004-04-19 17:53 UTC]
> $Id: common.php,v 1.21 2003/06/20 20:41:30 cox Exp $
> $Id: mysql.php,v 1.19 2003/06/21 16:45:26 cox Exp $
Those seem to be quite old files. mysql.php is currently at 1.71, in the DB-1.6.2 package.

You should try running "pear upgrade DB" to install the latest version of the PEAR::DB package, and see if that helps.
While you're at it, you might like to update the rest of PEAR aswell (running "pear upgrade-all" will do that), since the PEAR shipped with your SUSE seems to be quite outdated :)
 [2004-04-19 17:55 UTC]
The versions of the files you're using are dated 2003/06/20 and 2003/06/21.  The bug was fixed on 2003/08/28.  So, of course it's not fixed in the version you're using.

There have been significant fixes and enhancements to DB since then.  The current version is 1.6.2.  Update your installation.
 [2004-04-19 18:24 UTC] hubert dot christiaen at pandora dot be
Thansk for the VERY quick reactions! But even after updating to the latest versions (some 7/4/2004), the problem continues.

This is the code which worked correctly:
 $db->setFetchMode(DB_FETCHMODE_ASSOC) ;
 while ($qry->fetchInto($rowout)) { /*display the data */

but it works only if I put
 while ($qry->fetchInto($rowout,DB_FETCHMODE_ASSOC )) { /*display the data   */

Putting as tracing in mysql.php before lin 287 in fucntion fetchInto :
 echo "mysql.php: fetchmode = $fetchmode; this fetchmode = ".$this->fetchmode."<br>\n";
        if ($fetchmode & DB_FETCHMODE_ASSOC) {
gives as result:
mysql.php: fetchmode = 1; this fetchmode = 2

and I receive a numbered array instead of a associative array!
 [2004-04-19 18:37 UTC]
This works fine for me:

$db->query('CREATE TABLE blah (a integer)');
$db->query('INSERT INTO blah VALUES (5)');
$res =& $db->query('SELECT a FROM blah');
while ($res->fetchInto($row)) {
$db->query('DROP TABLE blah');

Seems like you have a bug in your script.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Aug 05 02:01:23 2021 UTC