summaryrefslogtreecommitdiffstats
path: root/modules/database/classes/driver
diff options
context:
space:
mode:
authorDracony <draconyster@gmail.com>2013-01-10 16:25:50 +0200
committerDracony <draconyster@gmail.com>2013-01-10 16:25:50 +0200
commit4161d1d639dee2df73a30f4872e5280205e5da2d (patch)
tree0e791ba6b4a7853fb66bbf947ab49880e47c07cf /modules/database/classes/driver
parenta5d20f2082ac7de829996d8df23af6bbc27a91d5 (diff)
downloadPHPixie-4161d1d639dee2df73a30f4872e5280205e5da2d.zip
PHPixie-4161d1d639dee2df73a30f4872e5280205e5da2d.tar.gz
PHPixie-4161d1d639dee2df73a30f4872e5280205e5da2d.tar.bz2
New format for config files.
Writing of config files now supported
Diffstat (limited to 'modules/database/classes/driver')
-rw-r--r--modules/database/classes/driver/mysql/db.php175
-rw-r--r--modules/database/classes/driver/mysql/query.php1
-rw-r--r--modules/database/classes/driver/mysql/result.php93
-rw-r--r--modules/database/classes/driver/pdo/db.php1
-rw-r--r--modules/database/classes/driver/pdo/query.php5
-rw-r--r--modules/database/classes/driver/pdo/result.php93
6 files changed, 187 insertions, 181 deletions
diff --git a/modules/database/classes/driver/mysql/db.php b/modules/database/classes/driver/mysql/db.php
index 553cfb9..879d1b8 100644
--- a/modules/database/classes/driver/mysql/db.php
+++ b/modules/database/classes/driver/mysql/db.php
@@ -1,88 +1,89 @@
-<?php
-
-/**
- * Mysqli Database Implementation
- */
-class DB_Mysql_Driver extends DB{
-
- /**
- * Mysqli database connection object
- * @var mysqli
- * @access public
- * @link http://php.net/manual/en/class.mysqli.php
- */
- public $conn;
-
- /**
- * Initializes database connection
- *
- * @param string $config Name of the connection to initialize
- * @return void
- * @access public
- */
- public function __construct($config) {
- $this->conn = mysqli_connect(
- Config::get("database.{$config}.host",'localhost'),
- Config::get("database.{$config}.user",''),
- Config::get("database.{$config}.password",''),
- Config::get("database.{$config}.db")
- );
- }
-
- /**
- * Builds a new Query implementation
- *
- * @param string $type Query type. Available types: select,update,insert,delete,count
- * @return Query_Mysql_Driver Returns a Mysqli implementation of a Query.
- * @access public
- * @see Query_Database
- */
- public function build_query($type) {
- return new Query_Mysql_Driver($this,$type);
- }
-
- /**
- * Gets the id of the last inserted row.
- *
- * @return mixed Row id
- * @access public
- */
- public function get_insert_id() {
- return $this->conn->insert_id;
- }
-
- /**
- * Executes a prepared statement query
- *
- * @param string $query A prepared statement query
- * @param array $params Parameters for the query
- * @return Result_Mysql_Driver Mysqli implementation of a database result
- * @access public
- * @throws Exception If the query resulted in an error
- * @see Database_Result
- */
- public function execute($query, $params = array()) {
- $cursor = $this->conn->prepare($query);
- if (!$cursor)
- throw new Exception("Database error: {$this->conn->error} \n in query:\n{$query}");
- $types = '';
- $bind = array();
- $refs = array();
- if(!empty($params)){
- foreach($params as $key=>$param) {
- $refs[$key]=is_array($param)?$param[0]:$param;
- $bind[]=&$refs[$key];
- $types.=is_array($param)?$param[1]:'s';
- }
- array_unshift($bind, $types);
-
- call_user_func_array(array($cursor, 'bind_param'), $bind);
- }
- $cursor->execute();
- $res = $cursor->get_result();
- if (is_object($res)){
- $res=new Result_Mysql_Driver($res);
- }
- return $res;
- }
+<?php
+
+/**
+ * Mysqli Database Implementation
+ * @package Database
+ */
+class DB_Mysql_Driver extends DB{
+
+ /**
+ * Mysqli database connection object
+ * @var mysqli
+ * @access public
+ * @link http://php.net/manual/en/class.mysqli.php
+ */
+ public $conn;
+
+ /**
+ * Initializes database connection
+ *
+ * @param string $config Name of the connection to initialize
+ * @return void
+ * @access public
+ */
+ public function __construct($config) {
+ $this->conn = mysqli_connect(
+ Config::get("database.{$config}.host",'localhost'),
+ Config::get("database.{$config}.user",''),
+ Config::get("database.{$config}.password",''),
+ Config::get("database.{$config}.db")
+ );
+ }
+
+ /**
+ * Builds a new Query implementation
+ *
+ * @param string $type Query type. Available types: select,update,insert,delete,count
+ * @return Query_Mysql_Driver Returns a Mysqli implementation of a Query.
+ * @access public
+ * @see Query_Database
+ */
+ public function build_query($type) {
+ return new Query_Mysql_Driver($this,$type);
+ }
+
+ /**
+ * Gets the id of the last inserted row.
+ *
+ * @return mixed Row id
+ * @access public
+ */
+ public function get_insert_id() {
+ return $this->conn->insert_id;
+ }
+
+ /**
+ * Executes a prepared statement query
+ *
+ * @param string $query A prepared statement query
+ * @param array $params Parameters for the query
+ * @return Result_Mysql_Driver Mysqli implementation of a database result
+ * @access public
+ * @throws Exception If the query resulted in an error
+ * @see Database_Result
+ */
+ public function execute($query, $params = array()) {
+ $cursor = $this->conn->prepare($query);
+ if (!$cursor)
+ throw new Exception("Database error: {$this->conn->error} \n in query:\n{$query}");
+ $types = '';
+ $bind = array();
+ $refs = array();
+ if(!empty($params)){
+ foreach($params as $key=>$param) {
+ $refs[$key]=is_array($param)?$param[0]:$param;
+ $bind[]=&$refs[$key];
+ $types.=is_array($param)?$param[1]:'s';
+ }
+ array_unshift($bind, $types);
+
+ call_user_func_array(array($cursor, 'bind_param'), $bind);
+ }
+ $cursor->execute();
+ $res = $cursor->get_result();
+ if (is_object($res)){
+ $res=new Result_Mysql_Driver($res);
+ }
+ return $res;
+ }
} \ No newline at end of file
diff --git a/modules/database/classes/driver/mysql/query.php b/modules/database/classes/driver/mysql/query.php
index e0ceacd..48b140e 100644
--- a/modules/database/classes/driver/mysql/query.php
+++ b/modules/database/classes/driver/mysql/query.php
@@ -2,6 +2,7 @@
/**
* Mysqli implementation of the database Query
+ * @package Database
*/
class Query_Mysql_Driver extends Query_PDO_Driver {
diff --git a/modules/database/classes/driver/mysql/result.php b/modules/database/classes/driver/mysql/result.php
index 0fbb645..a461c81 100644
--- a/modules/database/classes/driver/mysql/result.php
+++ b/modules/database/classes/driver/mysql/result.php
@@ -1,47 +1,48 @@
-<?php
-
-/**
- * Database result implementation for Mysqli
- */
-class Result_Mysql_Driver extends Result_Database {
-
- /**
- * Initializes new result object
- *
- * @param mysqli_result $result Mysqli Result
- * @return void
- * @access public
- * @link http://php.net/manual/en/class.mysqli-result.php
- */
- public function __construct($result) {
- $this->_result = $result;
- $this->_row=$this->_result->fetch_object();
- }
-
- /**
- * Throws exception if rewind is attempted.
- *
- * @return void
- * @access public
- * @throws Exception If rewind is attempted
- */
- public function rewind() {
- if($this->_position!=0)
- throw new Exception('Mysqli result cannot be rewound for unbuffered queries.');
- }
-
- /**
- * Iterates to the next row in the result set
- *
- * @return void
- * @access public
- */
- public function next() {
-
- $this->_position++;
- $this->_row=$this->_result->fetch_object();
- if ($this->_row == null)
- $this->_result->free();
- }
-
+<?php
+
+/**
+ * Database result implementation for Mysqli
+ * @package Database
+ */
+class Result_Mysql_Driver extends Result_Database {
+
+ /**
+ * Initializes new result object
+ *
+ * @param mysqli_result $result Mysqli Result
+ * @return void
+ * @access public
+ * @link http://php.net/manual/en/class.mysqli-result.php
+ */
+ public function __construct($result) {
+ $this->_result = $result;
+ $this->_row=$this->_result->fetch_object();
+ }
+
+ /**
+ * Throws exception if rewind is attempted.
+ *
+ * @return void
+ * @access public
+ * @throws Exception If rewind is attempted
+ */
+ public function rewind() {
+ if($this->_position!=0)
+ throw new Exception('Mysqli result cannot be rewound for unbuffered queries.');
+ }
+
+ /**
+ * Iterates to the next row in the result set
+ *
+ * @return void
+ * @access public
+ */
+ public function next() {
+
+ $this->_position++;
+ $this->_row=$this->_result->fetch_object();
+ if ($this->_row == null)
+ $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 18f278d..59705f7 100644
--- a/modules/database/classes/driver/pdo/db.php
+++ b/modules/database/classes/driver/pdo/db.php
@@ -2,6 +2,7 @@
/**
* PDO Database implementation.
+ * @package Database
*/
class DB_PDO_Driver extends DB{
diff --git a/modules/database/classes/driver/pdo/query.php b/modules/database/classes/driver/pdo/query.php
index 1102b44..662ce71 100644
--- a/modules/database/classes/driver/pdo/query.php
+++ b/modules/database/classes/driver/pdo/query.php
@@ -2,6 +2,7 @@
/**
* PDO implementation of the database Query
+ * @package Database
*/
class Query_PDO_Driver extends Query_Database {
@@ -218,11 +219,11 @@ class Query_PDO_Driver extends Query_Database {
}else {
$param = $this->escape_value($p['value'],$params);
}
- return $this->escape_field($p['field']).' '.$p['operator'].' '.$param;
+ return $this->escape_field($p['field']).' '.$p['operator'].' '.$param.' ';
}
if (isset($p['logic'])) {
return ($skip_first_operator?'':strtoupper($p['logic'])).' '
- .$this->get_condition_query($p['conditions'],$params,false,$value_is_field);
+ .$this->get_condition_query($p['conditions'],$params,false,$value_is_field).' ';
}
$conds = '';
diff --git a/modules/database/classes/driver/pdo/result.php b/modules/database/classes/driver/pdo/result.php
index 3270231..fec0652 100644
--- a/modules/database/classes/driver/pdo/result.php
+++ b/modules/database/classes/driver/pdo/result.php
@@ -1,47 +1,48 @@
-<?php
-
-/**
- * Database result implementation for PDO
- */
-class Result_PDO_Driver extends Result_Database {
-
- /**
- * Initializes new result object
- *
- * @param PDOStatement $stmt PDO Statement
- * @return void
- * @access public
- * @link http://php.net/manual/en/class.pdostatement.php
- */
- public function __construct($stmt) {
- $this->_result = $stmt;
- $this->_row=$this->_result->fetchObject();
- }
-
- /**
- * Throws exception if rewind is attempted.
- *
- * @return void
- * @access public
- * @throws Exception If rewind is attempted
- */
- public function rewind() {
- if($this->_position!=0)
- throw new Exception('PDO statement cannot be rewound for unbuffered queries');
- }
-
- /**
- * Iterates to the next row in the result set
- *
- * @return void
- * @access public
- */
- public function next() {
-
- $this->_position++;
- $this->_row=$this->_result->fetchObject();
- if ($this->_row == false)
- $this->_result->closeCursor();
- }
-
+<?php
+
+/**
+ * Database result implementation for PDO
+ * @package Database
+ */
+class Result_PDO_Driver extends Result_Database {
+
+ /**
+ * Initializes new result object
+ *
+ * @param PDOStatement $stmt PDO Statement
+ * @return void
+ * @access public
+ * @link http://php.net/manual/en/class.pdostatement.php
+ */
+ public function __construct($stmt) {
+ $this->_result = $stmt;
+ $this->_row=$this->_result->fetchObject();
+ }
+
+ /**
+ * Throws exception if rewind is attempted.
+ *
+ * @return void
+ * @access public
+ * @throws Exception If rewind is attempted
+ */
+ public function rewind() {
+ if($this->_position!=0)
+ throw new Exception('PDO statement cannot be rewound for unbuffered queries');
+ }
+
+ /**
+ * Iterates to the next row in the result set
+ *
+ * @return void
+ * @access public
+ */
+ public function next() {
+
+ $this->_position++;
+ $this->_row=$this->_result->fetchObject();
+ if ($this->_row == false)
+ $this->_result->closeCursor();
+ }
+
} \ No newline at end of file