cvs: php4 /pear/DB common.php
| From: | Stig Bakken | Date: | Tue, 25 Dec 2001 08:49:28 +0000 |
| Subject: | cvs: php4 /pear/DB common.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-1680@lists.php.net to get a copy of this message | ||
ssb Tue Dec 25 03:49:28 2001 EDT
Modified files:
/php4/pear/DB common.php
Log:
* implemented DB_FETCHMODE_ASSOC mode for getAssoc
Index: php4/pear/DB/common.php
diff -u php4/pear/DB/common.php:1.74 php4/pear/DB/common.php:1.75
--- php4/pear/DB/common.php:1.74 Thu Dec 13 18:07:30 2001
+++ php4/pear/DB/common.php Tue Dec 25 03:49:27 2001
@@ -17,7 +17,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: common.php,v 1.74 2001/12/13 23:07:30 alexmerz Exp $
+// $Id: common.php,v 1.75 2001/12/25 08:49:27 ssb Exp $
//
// Base class for DB implementations.
//
@@ -892,7 +892,8 @@
* @return array associative array with results from the query.
*/
- function &getAssoc($query, $force_array = false, $params = array())
+ function &getAssoc($query, $force_array = false, $params = array(),
+ $fetchmode = DB_FETCHMODE_ORDERED)
{
settype($params, "array");
if (sizeof($params) > 0) {
@@ -922,11 +923,20 @@
if ($cols > 2 || $force_array) {
// return array values
// XXX this part can be optimized
- while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
- 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);
+ if ($fetchmode == DB_FETCHMODE_ASSOC) {
+ while (is_array($row = $res->fetchRow(DB_FETCHMODE_ASSOC))) {
+ reset($row);
+ $key = current($row);
+ unset($row[key($row)]);
+ $results[$key] = $row;
+ }
+ } else {
+ while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
+ 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);
+ }
}
if (DB::isError($row)) {
$results = $row;