cvs: php4 /pear/Cache DB.php
| From: | Sebastian Bergmann | Date: | Tue, 14 Aug 2001 18:13:53 +0000 |
| Subject: | cvs: php4 /pear/Cache DB.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-513@lists.php.net to get a copy of this message | ||
sebastian Tue Aug 14 14:13:53 2001 EDT
Modified files:
/php4/pear/Cache DB.php
Log:
Call array_keys() only once per result set.
Index: php4/pear/Cache/DB.php
diff -u php4/pear/Cache/DB.php:1.1 php4/pear/Cache/DB.php:1.2
--- php4/pear/Cache/DB.php:1.1 Tue Aug 14 12:05:16 2001
+++ php4/pear/Cache/DB.php Tue Aug 14 14:13:53 2001
@@ -15,7 +15,7 @@
// | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: DB.php,v 1.1 2001/08/14 16:05:16 sebastian Exp $
+// $Id: DB.php,v 1.2 2001/08/14 18:13:53 sebastian Exp $
require_once 'Cache.php';
require_once 'DB.php';
@@ -31,7 +31,7 @@
* @module Cache_DB
* @modulegroup Cache_DB
* @package Cache
-* @version $Revision: 1.1 $
+* @version $Revision: 1.2 $
* @access public
*/
class Cache_DB extends Cache {
@@ -74,12 +74,14 @@
$_result = $this->db->query($query);
if (!DB::isError($_result)) {
- $result = new Cache_DB_Result;
+ $rows = array();
while ($row = $_result->fetchRow(DB_FETCHMODE_ASSOC)) {
- $result->rows[] = $row;
+ $rows[] = $row;
}
+ $result = new Cache_DB_Result($rows);
+
$this->save($cache_id, $result, $this->expires, 'db_cache');
} else {
return $_result;
@@ -100,12 +102,19 @@
* @module Cache_DB
* @modulegroup Cache_DB
* @package Cache
-* @version $Revision: 1.1 $
+* @version $Revision: 1.2 $
* @access public
*/
class Cache_DB_Result {
- var $rows = array();
- var $cursor = 0;
+ var $rows = array();
+ var $columns = array();
+ var $cursor = 0;
+
+ function Cache_DB_Result(&$rows) {
+ $this->rows = $rows;
+ $this->columns = array_keys($this->rows[0]);
+ $this->cursor = 0;
+ }
function fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null) {
if ($this->cursor < sizeof($this->rows)) {
@@ -114,12 +123,10 @@
}
elseif ($fetchmode == DB_FETCHMODE_ORDERED) {
+ $row = array();
$_row = $this->rows[$this->cursor++];
- $columns = array_keys($_row);
- $row = array();
-
- foreach ($columns as $column) {
+ foreach ($this->columns as $column) {
$row[] = $_row[$column];
}