From 37b4f889c91f5a41668ea446b83a7aa429ac35a8 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 16 Dec 2006 23:56:46 +0000 Subject: [PATCH] Updated MySQLi wrapper --- db_mysqli.php | 150 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 103 insertions(+), 47 deletions(-) diff --git a/db_mysqli.php b/db_mysqli.php index 72e56fa..0cef671 100644 --- a/db_mysqli.php +++ b/db_mysqli.php @@ -20,16 +20,15 @@ \*=====================================================================*/ /** -* MySQLi Database Abstraction Layer -* db_mysqli.php +* MySQLi Database Layer (DbMySqlI.php) * * @package ISSO */ -$this->load('db', null); +require_once('ISSO/Db.php'); /** -* MySQLi Database Abstraction Layer +* MySQLi Database Layer * * This framework is a function wrapper for MySQLi functions so we can have * better error reporting and query reporting. @@ -40,73 +39,130 @@ $this->load('db', null); * @package ISSO * */ -class DB_MySQLi extends DB_Abstract +class BSDbMySqlI extends BSDb { + // ################################################################### /** - * Command mapping list - * @var array + * Wrapper: mysql_connect */ - private $commands = array( - 'pconnect' => '$this->command_mysqli_connect', - 'connect' => '$this->command_mysqli_connect', - 'query' => 'mysqli_query', - 'error_num' => 'mysqli_errno', - 'error_str' => 'mysqli_error', - 'escape_string' => 'mysqli_real_escape_string', - 'escape_binary' => 'mysqli_real_escape_string', - 'unescape_binary' => '$this->command_unescape_binary', - 'fetch_assoc' => 'mysqli_fetch_assoc', - 'fetch_row' => 'mysqli_fetch_row', - 'fetch_object' => 'mysqli_fetch_object', - 'free_result' => 'mysqli_free_result', - 'insert_id' => 'mysqli_insert_id', - 'num_rows' => 'mysqli_num_rows', - 'affected_rows' => 'mysqli_affected_rows' - ); + protected function _connect($server, $user, $password, $database) + { + return mysqli_connect($server, $user, $password, $database); + } // ################################################################### /** - * Constructor + * Wrapper: mysql_pconnect */ - public function __construct(&$registry) + protected function _pConnect($server, $user, $password, $database) { - parent::__construct($registry); + return mysqli_connect($server, $user, $password, $database); } - + // ################################################################### /** - * Wrapper: mysqli_connect - * - * @param string Server name - * @param string User name - * @param string Password - * @param string Database - * - * @return integer DB-Link + * Wrapper: mysql_query */ - protected function command_mysqli_connect($server, $user, $password, $database) + protected function _query($string) { - return mysqli_connect($server, $user, $password, $database); + return mysqli_query($this->dblink, $string); + } + + // ################################################################### + /** + * Wrapper: mysql_escape_string + */ + protected function _escapeBinary($binary) + { + return mysqli_real_escape_string($this->dblink, $binary); + } + + // ################################################################### + /** + * Wrapper: mysql(_real)_escape_string + */ + protected function _escapeString($string) + { + return mysqli_real_escape_string($this->dblink, $string); } // ################################################################### /** * Not supported: unescape binary string - * - * @param string Escaped data - * - * @return string Same data */ - protected function command_unescape_binary($string) + protected function _unescapeBinary($string) { return $string; } + // ################################################################### + /** + * Wrapper: mysql_fetch_assoc + */ + protected function _fetchAssocArray($result) + { + return mysqli_fetch_assoc($result); + } + + // ################################################################### + /** + * Wrapper: mysql_fetch_row + */ + protected function _fetchRowArray($result) + { + return mysqli_fetch_row($result); + } + + // ################################################################### + /** + * Wrapper: mysql_fetch_object + */ + public function _fetchObject($result) + { + return mysqli_fetch_object($result); + } + + // ################################################################### + /** + * Wrapper: mysql_free_result + */ + protected function _freeResult($result) + { + mysqli_free_result($result); + } + + // ################################################################### + /** + * Wrapper: mysql_insert_id + */ + protected function _insertId() + { + return mysqli_insert_id($this->dblink); + } + + // ################################################################### + /** + * Wrapper: mysql_num_rows + */ + protected function _numRows($result) + { + return mysqli_num_rows($result); + } + + // ################################################################### + /** + * Wrapper: mysql_affected_rows + */ + protected function _affectedRows($result) + { + return mysqli_affected_rows($this->dblink); + } + // ################################################################### /** * Starts a database transaction */ - public function transaction_start() + public function transactionStart() { $this->query("START TRANSACTION"); } @@ -117,7 +173,7 @@ class DB_MySQLi extends DB_Abstract * * @param string Named savepoint */ - public function transaction_savepoint($name) + public function transactionSavepoint($name) { $this->query("SAVEPOINT $name"); } @@ -128,7 +184,7 @@ class DB_MySQLi extends DB_Abstract * * @param string Named savepoint */ - public function transaction_rollback($name = null) + public function transactionRollback($name = null) { $this->query("ROLLBACK" . ($name != null ? " TO SAVEPOINT $name" : "")); } @@ -137,7 +193,7 @@ class DB_MySQLi extends DB_Abstract /** * Commits a database transaction */ - public function transaction_commit() + public function transactionCommit() { $this->query("COMMIT"); } -- 2.22.5