summaryrefslogtreecommitdiffstats
path: root/modules/database/classes/driver/mysql
diff options
context:
space:
mode:
authorVolker Thiel <riker09@gmx.de>2013-03-07 08:42:58 +0100
committerVolker Thiel <riker09@gmx.de>2013-03-07 08:42:58 +0100
commit2e8b8467e22f984b42a25b1d90c1a3a19ea4a99d (patch)
tree0efb570d95c55ab34e5089a2497c56bc5abd05f6 /modules/database/classes/driver/mysql
parenta15002166676ebad5078ee1aa5c8b3365295496d (diff)
downloadPHPixie-2e8b8467e22f984b42a25b1d90c1a3a19ea4a99d.zip
PHPixie-2e8b8467e22f984b42a25b1d90c1a3a19ea4a99d.tar.gz
PHPixie-2e8b8467e22f984b42a25b1d90c1a3a19ea4a99d.tar.bz2
Applied coding guidelines to more files
Increases readability
Diffstat (limited to 'modules/database/classes/driver/mysql')
-rw-r--r--modules/database/classes/driver/mysql/db.php133
-rw-r--r--modules/database/classes/driver/mysql/result.php45
2 files changed, 99 insertions, 79 deletions
diff --git a/modules/database/classes/driver/mysql/db.php b/modules/database/classes/driver/mysql/db.php
index 0b2e03f..88df9b8 100644
--- a/modules/database/classes/driver/mysql/db.php
+++ b/modules/database/classes/driver/mysql/db.php
@@ -4,23 +4,24 @@
* Mysqli Database Implementation
* @package Database
*/
-class DB_Mysql_Driver extends DB{
+class DB_Mysql_Driver extends DB
+{
/**
* Mysqli database connection object
* @var mysqli
* @access public
- * @link http://php.net/manual/en/class.mysqli.php
+ * @link http://php.net/manual/en/class.mysqli.php
*/
- public $conn;
-
- /**
+ public $conn;
+
+ /**
* Type of the database, mysql.
* @var string
* @access public
*/
- public $db_type='mysql';
-
+ public $db_type = 'mysql';
+
/**
* Initializes database connection
*
@@ -28,47 +29,51 @@ class DB_Mysql_Driver extends DB{
* @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")
- );
- $this->conn->set_charset("utf8");
- }
-
- /**
+ 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")
+ );
+ $this->conn->set_charset("utf8");
+ }
+
+ /**
* Gets column names for the specified table
*
- * @param string $table Name of the table to get columns from
+ * @param string $table Name of the table to get columns from
* @return array Array of column names
- * @throw Exception if table doesn't exist
+ * @throw Exception if table doesn't exist
* @access public
*/
- public function list_columns($table) {
- $columns=array();
- $table_desc = $this->execute("DESCRIBE `$table`");
- Debug::log($table_desc);
- if (!$table_desc->valid())
- throw new Exception("Table '{$table}' doesn't exist");
- foreach($table_desc as $column)
- $columns[] = $column->Field;
-
- return $columns;
- }
-
+ public function list_columns($table)
+ {
+ $columns = array();
+ $table_desc = $this->execute("DESCRIBE `$table`");
+ Debug::log($table_desc);
+ if (!$table_desc->valid())
+ {
+ throw new Exception("Table '{$table}' doesn't exist");
+ }
+ foreach ($table_desc as $column)
+ {
+ $columns[] = $column->Field;
+ }
+
+ return $columns;
+ }
+
/**
* 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
+ * @see Query_Database
*/
- public function build_query($type) {
- return new Query_Mysql_Driver($this,$type);
- }
+ public function build_query($type)
+ {
+ return new Query_Mysql_Driver($this, $type);
+ }
/**
* Gets the id of the last inserted row.
@@ -76,9 +81,10 @@ class DB_Mysql_Driver extends DB{
* @return mixed Row id
* @access public
*/
- public function get_insert_id() {
- return $this->conn->insert_id;
- }
+ public function get_insert_id()
+ {
+ return $this->conn->insert_id;
+ }
/**
* Executes a prepared statement query
@@ -88,28 +94,33 @@ class DB_Mysql_Driver extends DB{
* @return Result_Mysql_Driver Mysqli implementation of a database result
* @access public
* @throws Exception If the query resulted in an error
- * @see Database_Result
+ * @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();
- return new Result_Mysql_Driver($res);
+ 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();
+ return new Result_Mysql_Driver($res);
+ }
- }
} \ 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 a2b2a90..e9de4a5 100644
--- a/modules/database/classes/driver/mysql/result.php
+++ b/modules/database/classes/driver/mysql/result.php
@@ -4,7 +4,8 @@
* Database result implementation for Mysqli
* @package Database
*/
-class Result_Mysql_Driver extends Result_Database {
+class Result_Mysql_Driver extends Result_Database
+{
/**
* Initializes new result object
@@ -12,11 +13,12 @@ class Result_Mysql_Driver extends Result_Database {
* @param mysqli_result $result Mysqli Result
* @return void
* @access public
- * @link http://php.net/manual/en/class.mysqli-result.php
+ * @link http://php.net/manual/en/class.mysqli-result.php
*/
- public function __construct($result) {
- $this->_result = $result;
- }
+ public function __construct($result)
+ {
+ $this->_result = $result;
+ }
/**
* Throws exception if rewind is attempted.
@@ -25,25 +27,32 @@ class Result_Mysql_Driver extends Result_Database {
* @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.');
+ 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->check_fetched();
- $this->_row = $this->_result->fetch_object();
- if ($this->_row) {
- $this->_position++;
- }else {
- $this->_result->free();
- }
+ public function next()
+ {
+ $this->check_fetched();
+ $this->_row = $this->_result->fetch_object();
+ if ($this->_row)
+ {
+ $this->_position++;
+ }
+ else
+ {
+ $this->_result->free();
+ }
}
-
+
} \ No newline at end of file