cvs: php4 /pear DB.php

From: Date: Fri, 03 Aug 2001 14:13:52 +0000
Subject: cvs: php4 /pear DB.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-413@lists.php.net to get a copy of this message
cox Fri Aug 3 10:13:52 2001 EDT Modified files: /php4/pear DB.php Log: * Added the new fetch row mode: DB_FETCHMODE_OBJECT that returns the columns of a fetched row as object properties * Added a new class DB_row (the default type of a fetched row object) * Updated some phpdocs Index: php4/pear/DB.php diff -u php4/pear/DB.php:1.72 php4/pear/DB.php:1.73 --- php4/pear/DB.php:1.72 Wed Jul 25 20:01:27 2001 +++ php4/pear/DB.php Fri Aug 3 10:13:52 2001 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: DB.php,v 1.72 2001/07/26 00:01:27 cox Exp $ +// $Id: DB.php,v 1.73 2001/08/03 14:13:52 cox Exp $ // // Database independent query interface. // @@ -124,6 +124,12 @@ define('DB_FETCHMODE_ASSOC', 2); /** +* Column data as object properties +*/ + +define('DB_FETCHMODE_OBJECT', 3); + +/** * For multi-dimensional results: normally the first level of arrays * is the row number, and the second level indexed by column number or name. * DB_FETCHMODE_FLIPPED switches this order, so the first level of arrays @@ -612,40 +618,58 @@ } /** - * Fetch and return a row of data (it uses fetchInto for that) - * @param $fetchmode format of fetched row array - * @param $rownum the absolute row number to fetch + * 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 * - * @return array a row of data, or false 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) { if ($fetchmode === DB_FETCHMODE_DEFAULT) { $fetchmode = $this->dbh->fetchmode; } - + if ($fetchmode === DB_FETCHMODE_OBJECT) { + $fetchmode = DB_FETCHMODE_ASSOC; + $return_object = true; + } $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum); if ($res !== DB_OK) { return $res; } + if (isset($return_object)) { + $class = $this->dbh->fetchmode_object_class; + $ret =& new $class($arr); + return $ret; + } return $arr; } /** - * Fetch a row of data into an existing array. + * Fetch a row of data into an existing variable. * - * @param $arr reference to data array - * @param $fetchmode format of fetched row array - * @param $rownum the absolute row number to fetch + * @param $arr reference to data containing the row + * @param $fetchmode format of fetched row + * @param $rownum the row number to fetch * - * @return int error code + * @return mixed DB_OK on success, NULL on no more rows or + * a DB_Error object on errors */ function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) { if ($fetchmode === DB_FETCHMODE_DEFAULT) { $fetchmode = $this->dbh->fetchmode; } - return $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum); + if ($fetchmode === DB_FETCHMODE_OBJECT) { + $fetchmode = DB_FETCHMODE_ASSOC; + $return_object = true; + } + $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); + } + return $res; } /** @@ -688,4 +712,14 @@ } } -?> +class DB_row +{ + function DB_row(&$arr) + { + for (reset($arr); $key = key($arr); next($arr)) { + $this->$key = &$arr[$key]; + } + } +} + +?> \ No newline at end of file

« previous php.pear.cvs (#413) next »