diff options
author | Dracony <draconyster@gmail.com> | 2013-02-04 19:03:56 +0200 |
---|---|---|
committer | Dracony <draconyster@gmail.com> | 2013-02-04 19:03:56 +0200 |
commit | febbbebecccfab3eb129cfcdc880e65b2a72e295 (patch) | |
tree | 328968ed7f9a383751f19c58624c09685a4f8da9 /modules/database | |
parent | 1fd53f9bcb1a820002ac3e608573fd6d1c139622 (diff) | |
download | PHPixie-febbbebecccfab3eb129cfcdc880e65b2a72e295.zip PHPixie-febbbebecccfab3eb129cfcdc880e65b2a72e295.tar.gz PHPixie-febbbebecccfab3eb129cfcdc880e65b2a72e295.tar.bz2 |
almost done with caching
Diffstat (limited to 'modules/database')
-rw-r--r-- | modules/database/classes/database/result.php | 20 | ||||
-rw-r--r-- | modules/database/classes/driver/mysql/result.php | 8 | ||||
-rw-r--r-- | modules/database/classes/driver/pdo/db.php | 1 | ||||
-rw-r--r-- | modules/database/classes/driver/pdo/result.php | 7 |
4 files changed, 27 insertions, 9 deletions
diff --git a/modules/database/classes/database/result.php b/modules/database/classes/database/result.php index 8b80ac2..5802a96 100644 --- a/modules/database/classes/database/result.php +++ b/modules/database/classes/database/result.php @@ -28,6 +28,12 @@ abstract class Result_Database implements Iterator { */
protected $_row;
+ /**
+ * If at least one row has been fetched
+ * @var object
+ * @access protected
+ */
+ protected $_fetched = false;
/**
* Returns current row
@@ -36,6 +42,7 @@ abstract class Result_Database implements Iterator { * @access public
*/
public function current() {
+ $this->check_fetched();
return $this->_row;
}
@@ -46,6 +53,7 @@ abstract class Result_Database implements Iterator { * @access public
*/
public function key() {
+ $this->check_fetched();
return $this->_position;
}
@@ -56,6 +64,7 @@ abstract class Result_Database implements Iterator { * @access public
*/
public function valid() {
+ $this->check_fetched();
return $this->_row!=null;
}
@@ -72,4 +81,15 @@ abstract class Result_Database implements Iterator { return $arr;
}
+ public function check_fetched() {
+ if (!$this->_fetched)
+ $this->next();
+ $this->_fetched=true;
+ }
+
+ public function get($column) {
+ if ($this->valid() && isset($this->_row->$column))
+ return $this->_row->$column;
+ }
+
}
\ No newline at end of file diff --git a/modules/database/classes/driver/mysql/result.php b/modules/database/classes/driver/mysql/result.php index f058a97..ccbdfcf 100644 --- a/modules/database/classes/driver/mysql/result.php +++ b/modules/database/classes/driver/mysql/result.php @@ -16,8 +16,6 @@ class Result_Mysql_Driver extends Result_Database { */
public function __construct($result) {
$this->_result = $result;
- if(!empty($result))
- $this->_row=$this->_result->fetch_object();
}
/**
@@ -39,11 +37,11 @@ class Result_Mysql_Driver extends Result_Database { * @access public
*/
public function next() {
-
- $this->_position++;
+ if($this->_fetched)
+ $this->_position++;
$this->_row=$this->_result->fetch_object();
if ($this->_row == null)
- $this->_result->free();
+ $this->_result->free();
}
}
\ No newline at end of file diff --git a/modules/database/classes/driver/pdo/db.php b/modules/database/classes/driver/pdo/db.php index ac15258..8390cf0 100644 --- a/modules/database/classes/driver/pdo/db.php +++ b/modules/database/classes/driver/pdo/db.php @@ -34,6 +34,7 @@ class DB_PDO_Driver extends DB{ Config::get("database.{$config}.user",''),
Config::get("database.{$config}.password",'')
);
+ $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->db_type = strtolower(str_replace('PDO_', '', $this->conn->getAttribute(PDO::ATTR_DRIVER_NAME)));
if($this->db_type!='sqlite')
$this->execute("SET NAMES utf8");
diff --git a/modules/database/classes/driver/pdo/result.php b/modules/database/classes/driver/pdo/result.php index fec0652..943dec7 100644 --- a/modules/database/classes/driver/pdo/result.php +++ b/modules/database/classes/driver/pdo/result.php @@ -16,7 +16,6 @@ class Result_PDO_Driver extends Result_Database { */
public function __construct($stmt) {
$this->_result = $stmt;
- $this->_row=$this->_result->fetchObject();
}
/**
@@ -38,11 +37,11 @@ class Result_PDO_Driver extends Result_Database { * @access public
*/
public function next() {
-
- $this->_position++;
+ if($this->_fetched)
+ $this->_position++;
$this->_row=$this->_result->fetchObject();
if ($this->_row == false)
- $this->_result->closeCursor();
+ $this->_result->closeCursor();
}
}
\ No newline at end of file |