]> granicus.if.org Git - php/commitdiff
- By default DB_FETCHMODE_OBJECT will do a cast to object from the row
authorTomas V.V.Cox <cox@php.net>
Thu, 8 Nov 2001 13:53:44 +0000 (13:53 +0000)
committerTomas V.V.Cox <cox@php.net>
Thu, 8 Nov 2001 13:53:44 +0000 (13:53 +0000)
  array (twice fast than with DB_Row)
- API Doc updates/fixs

pear/DB.php

index 5f0a536688e9d0a720940248529259d521ff46cd..d4ade674b4bb0f7db012984fb738e5d8263d2d72 100644 (file)
@@ -615,11 +615,11 @@ class DB_result
     }
 
     /**
-     * Fetch and return a row of data (it uses backend->fetchInto for that)
-     * @param   $fetchmode  format of fetched row
-     * @param   $rownum     the row number to fetch
+     * Fetch and return a row of data (it uses driver->fetchInto for that)
+     * @param int $fetchmode  format of fetched row
+     * @param int $rownum     the row number to fetch
      *
-     * @return  array   a row of data, NULL on no more rows or PEAR_Error on error
+     * @return  array a row of data, NULL on no more rows or PEAR_Error on error
      */
     function fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
     {
@@ -628,7 +628,7 @@ class DB_result
         }
         if ($fetchmode === DB_FETCHMODE_OBJECT) {
             $fetchmode = DB_FETCHMODE_ASSOC;
-            $return_object = true;
+            $object_class = $this->dbh->fetchmode_object_class;
         }
         if ($this->dbh->limit_from !== null) {
             if ($this->row_counter === null) {
@@ -656,9 +656,13 @@ class DB_result
         if ($res !== DB_OK) {
             return $res;
         }
-        if (isset($return_object)) {
-            $class = $this->dbh->fetchmode_object_class;
-            $ret =& new $class($arr);
+        if (isset($object_class)) {
+            // default mode specified in DB_common::fetchmode_object_class property
+            if ($object_class == 'stdClass') {
+                $ret = (object) $arr;
+            } else {
+                $ret =& new $object_class($arr);
+            }
             return $ret;
         }
         return $arr;
@@ -667,12 +671,12 @@ class DB_result
     /**
      * Fetch a row of data into an existing variable.
      *
-     * @param   $arr        reference to data containing the row
-     * @param   $fetchmode  format of fetched row
-     * @param   $rownum     the row number to fetch
+     * @param  mixed $arr        reference to data containing the row
+     * @param  int   $fetchmode  format of fetched row
+     * @param  int   $rownum     the row number to fetch
      *
      * @return  mixed  DB_OK on success, NULL on no more rows or
-     *                 a DB_Error object on errors
+     *                 a DB_Error object on error
      */
     function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
     {
@@ -681,7 +685,7 @@ class DB_result
         }
         if ($fetchmode === DB_FETCHMODE_OBJECT) {
             $fetchmode = DB_FETCHMODE_ASSOC;
-            $return_object = true;
+            $object_class = $this->dbh->fetchmode_object_class;
         }
         if ($this->dbh->limit_from !== null) {
             if ($this->row_counter === null) {
@@ -706,9 +710,13 @@ class DB_result
             $this->row_counter++;
         }
         $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
-        if (($res === DB_OK) && isset($return_object)) {
-            $class = $this->dbh->fetchmode_object_class;
-            $arr = new $class($arr);
+        if (($res === DB_OK) && isset($object_class)) {
+            // default mode specified in DB_common::fetchmode_object_class property
+            if ($object_class == 'stdClass') {
+                $arr = (object) $arr;
+            } else {
+                $arr = new $object_class($arr);
+            }
         }
         return $res;
     }
@@ -768,6 +776,10 @@ class DB_result
     }
 }
 
+/**
+* Pear DB Row Object
+* @see DB_common::setFetchMode()
+*/
 class DB_row
 {
     function DB_row(&$arr)