cvs: php4 /pear DB.php /pear/DB common.php
| From: | Thomas V.V.Cox | Date: | Thu, 08 Nov 2001 13:53:45 +0000 |
| Subject: | cvs: php4 /pear DB.php /pear/DB common.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-1281@lists.php.net to get a copy of this message | ||
cox Thu Nov 8 08:53:45 2001 EDT
Modified files:
/php4/pear DB.php
/php4/pear/DB common.php
Log:
- By default DB_FETCHMODE_OBJECT will do a cast to object from the row
array (twice fast than with DB_Row)
- API Doc updates/fixs
Index: php4/pear/DB.php
diff -u php4/pear/DB.php:1.78 php4/pear/DB.php:1.79
--- php4/pear/DB.php:1.78 Thu Nov 1 19:38:23 2001
+++ php4/pear/DB.php Thu Nov 8 08:53:44 2001
@@ -17,7 +17,7 @@
// | Tomas V.V.Cox <cox@idecnet.com> |
// +----------------------------------------------------------------------+
//
-// $Id: DB.php,v 1.78 2001/11/02 00:38:23 cox Exp $
+// $Id: DB.php,v 1.79 2001/11/08 13:53:44 cox Exp $
//
// Database independent query interface.
//
@@ -615,11 +615,11 @@
}
/**
- * 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 @@
}
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 @@
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 @@
/**
* 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 @@
}
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 @@
$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 @@
}
}
+/**
+* Pear DB Row Object
+* @see DB_common::setFetchMode()
+*/
class DB_row
{
function DB_row(&$arr)
Index: php4/pear/DB/common.php
diff -u php4/pear/DB/common.php:1.69 php4/pear/DB/common.php:1.70
--- php4/pear/DB/common.php:1.69 Thu Nov 1 19:41:27 2001
+++ php4/pear/DB/common.php Thu Nov 8 08:53:44 2001
@@ -17,7 +17,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: common.php,v 1.69 2001/11/02 00:41:27 cox Exp $
+// $Id: common.php,v 1.70 2001/11/08 13:53:44 cox Exp $
//
// Base class for DB implementations.
//
@@ -40,7 +40,7 @@
var $prepare_maxstmt = 0;
var $last_query = '';
var $fetchmode = DB_FETCHMODE_ORDERED;
- var $fetchmode_object_class = 'DB_row';
+ var $fetchmode_object_class = 'stdClass';
var $limit_from = null; // for limit queries, the row to start fetching
var $limit_count = null; // for limit queries, the number of rows to fetch
var $options = array(
@@ -243,11 +243,16 @@
* @param $object_class string optional The class of the object
* to be returned by the fetch methods when
* the DB_FETCHMODE_OBJECT mode is selected.
+ * If no class is specified by default a cast
+ * to object from the assoc array row will be done.
+ * There is also the posibility to use and extend the
+ * 'DB_Row' class.
*
* @see DB_FETCHMODE_ORDERED
* @see DB_FETCHMODE_ASSOC
* @see DB_FETCHMODE_FLIPPED
* @see DB_FETCHMODE_OBJECT
+ * @see DB_Row::DB_Row()
*/
function setFetchMode($fetchmode, $object_class = null)