Index: branches/5.2.x/core/kernel/startup.php =================================================================== diff -u -N -r16117 -r16407 --- branches/5.2.x/core/kernel/startup.php (.../startup.php) (revision 16117) +++ branches/5.2.x/core/kernel/startup.php (.../startup.php) (revision 16407) @@ -1,6 +1,6 @@ &1'); Index: branches/5.2.x/core/kernel/db/db_connection.php =================================================================== diff -u -N -r15552 -r16407 --- branches/5.2.x/core/kernel/db/db_connection.php (.../db_connection.php) (revision 15552) +++ branches/5.2.x/core/kernel/db/db_connection.php (.../db_connection.php) (revision 16407) @@ -1,6 +1,6 @@ dbType = $dbType; $this->serverIndex = $server_index; -// $this->initMetaFunctions(); - if (!$errorHandler) { + if ( !$error_handler ) { $this->errorHandler = Array(&$this, 'handleError'); } else { - $this->errorHandler = $errorHandler; + $this->errorHandler = $error_handler; } $this->_captureStatistics = defined('DBG_CAPTURE_STATISTICS') && DBG_CAPTURE_STATISTICS && !(defined('ADMIN') && ADMIN); @@ -214,44 +196,6 @@ } /** - * Caches function specific to requested - * db type - * - * @access protected - */ - protected function initMetaFunctions() - { - $ret = Array (); - - switch ( $this->dbType ) { - case 'mysql': - $ret = Array (); // only define functions, that name differs from "dbType_" - - break; - } - - $this->metaFunctions = $ret; - } - - /** - * Gets function for specific db type - * based on it's meta name - * - * @param string $name - * @return string - * @access protected - */ - protected function getMetaFunction($name) - { - /*if ( !isset($this->metaFunctions[$name]) ) { - $this->metaFunctions[$name] = $name; - }*/ - - return $this->dbType . '_' . $name; - } - - - /** * Try to connect to database server * using specified parameters and set * database to $db if connection made @@ -260,43 +204,36 @@ * @param string $user * @param string $pass * @param string $db - * @param bool $force_new - * @param bool $retry + * @param bool $retry + * * @return bool * @access public */ - public function Connect($host, $user, $pass, $db, $force_new = false, $retry = false) + public function Connect($host, $user, $pass, $db, $retry = false) { $this->connectionParams = Array ('host' => $host, 'user' => $user, 'pass' => $pass, 'db' => $db); - $func = $this->getMetaFunction('connect'); - $this->connectionID = $func($host, $user, $pass, $force_new); + $this->setError(0, ''); // reset error + $this->connectionID = mysqli_connect($host, $user, $pass, $db); + $this->errorCode = mysqli_connect_errno(); - if ($this->connectionID) { - if (defined('DBG_SQL_MODE')) { - $this->Query('SET sql_mode = \''.DBG_SQL_MODE.'\''); + if ( is_object($this->connectionID) ) { + if ( defined('DBG_SQL_MODE') ) { + $this->Query('SET SQL_MODE = "' . DBG_SQL_MODE . '"'); } - if (defined('SQL_COLLATION') && defined('SQL_CHARSET')) { - $this->Query('SET NAMES \''.SQL_CHARSET.'\' COLLATE \''.SQL_COLLATION.'\''); + if ( defined('SQL_COLLATION') && defined('SQL_CHARSET') ) { + $this->Query('SET NAMES \'' . SQL_CHARSET . '\' COLLATE \'' . SQL_COLLATION . '\''); } - $this->setError(0, ''); // reset error - $this->setDB($db); - } + if ( !$this->hasError() ) { + $this->connectionOpened = true; - // process error (fatal in most cases) - $func = $this->getMetaFunction('errno'); - $this->errorCode = $this->connectionID ? $func($this->connectionID) : $func(); - - if ( is_resource($this->connectionID) && !$this->hasError() ) { - $this->connectionOpened = true; - - return true; + return true; + } } - $func = $this->getMetaFunction('error'); - $this->errorMessage = $this->connectionID ? $func($this->connectionID) : $func(); + $this->errorMessage = mysqli_connect_error(); $error_msg = 'Database connection failed, please check your connection settings.
Error (' . $this->errorCode . '): ' . $this->errorMessage; if ( (defined('IS_INSTALL') && IS_INSTALL) || $retry ) { @@ -348,17 +285,15 @@ /** * Performs 3 reconnect attempts in case if connection to a DB was lost in the middle of script run (e.g. server restart) * - * @param bool $force_new * @return bool * @access protected */ - protected function ReConnect($force_new = false) + protected function ReConnect() { $retry_count = 0; $connected = false; - $func = $this->getMetaFunction('close'); - $func($this->connectionID); + $this->connectionID->close(); while ( $retry_count < 3 ) { sleep(5); // wait 5 seconds before each reconnect attempt @@ -368,7 +303,7 @@ $this->connectionParams['user'], $this->connectionParams['pass'], $this->connectionParams['db'], - $force_new, true + true ); if ( $connected ) { @@ -395,15 +330,12 @@ { static $retry_count = 0; - $func = $this->getMetaFunction('errno'); - - if (!$this->connectionID) { + if ( !is_object($this->connectionID) ) { // no connection while doing mysql_query - $this->errorCode = $func(); + $this->errorCode = mysqli_connect_errno(); if ( $this->hasError() ) { - $func = $this->getMetaFunction('error'); - $this->errorMessage = $func(); + $this->errorMessage = mysqli_connect_error(); $ret = $this->callErrorHandler($sql); @@ -416,11 +348,10 @@ } // checking if there was an error during last mysql_query - $this->errorCode = $func($this->connectionID); + $this->errorCode = $this->connectionID->errno; if ( $this->hasError() ) { - $func = $this->getMetaFunction('error'); - $this->errorMessage = $func($this->connectionID); + $this->errorMessage = $this->connectionID->error; $ret = $this->callErrorHandler($sql); @@ -484,21 +415,6 @@ } /** - * Set's database name for connection - * to $new_name - * - * @param string $new_name - * @return bool - * @access protected - */ - protected function setDB($new_name) - { - if (!$this->connectionID) return false; - $func = $this->getMetaFunction('select_db'); - return $func($new_name, $this->connectionID); - } - - /** * Returns first field of first line * of recordset if query ok or false * otherwise @@ -611,26 +527,23 @@ $this->_queryCount++; $this->lastQuery = $sql; - $query_func = $this->getMetaFunction('query'); - // set 1st checkpoint: begin $start_time = $this->_captureStatistics ? microtime(true) : 0; // set 1st checkpoint: end $this->setError(0, ''); // reset error - $this->queryID = $query_func($sql, $this->connectionID); + $this->queryID = $this->connectionID->query($sql); - if ( is_resource($this->queryID) ) { + if ( is_object($this->queryID) ) { $ret = Array (); - $fetch_func = $this->getMetaFunction('fetch_assoc'); if ( isset($key_field) ) { - while (($row = $fetch_func($this->queryID))) { + while ( $row = $this->queryID->fetch_assoc() ) { $ret[$row[$key_field]] = $row; } } else { - while (($row = $fetch_func($this->queryID))) { + while ( $row = $this->queryID->fetch_assoc() ) { $ret[] = $row; } } @@ -679,16 +592,14 @@ $this->_queryCount++; $this->lastQuery = $sql; - $query_func = $this->getMetaFunction('query'); - // set 1st checkpoint: begin $start_time = $this->_captureStatistics ? microtime(true) : 0; // set 1st checkpoint: end $this->setError(0, ''); // reset error - $this->queryID = $query_func($sql, $this->connectionID); + $this->queryID = $this->connectionID->query($sql); - if ( is_resource($this->queryID) ) { + if ( is_object($this->queryID) ) { $ret = new $iterator_class($this->queryID, $key_field); /* @var $ret kMySQLQuery */ @@ -724,9 +635,7 @@ */ public function Destroy() { - $free_func = $this->getMetaFunction('free_result'); - $free_func($this->queryID); - + $this->queryID->free(); unset($this->queryID); } @@ -755,8 +664,7 @@ */ public function getInsertID() { - $func = $this->getMetaFunction('insert_id'); - return $func($this->connectionID); + return $this->connectionID->insert_id; } /** @@ -767,8 +675,7 @@ */ public function getAffectedRows() { - $func = $this->getMetaFunction('affected_rows'); - return $func($this->connectionID); + return $this->connectionID->affected_rows; } /** @@ -785,11 +692,7 @@ return ''; } - switch ( $this->dbType ) { - default: - return 'LIMIT ' . $offset . ',' . $rows; - break; - } + return 'LIMIT ' . $offset . ',' . $rows; } /** @@ -810,7 +713,7 @@ # and protects against weird problems that occur when they really # _are_ strings such as article titles and string->number->string # conversion is not 1:1. - return "'" . mysql_real_escape_string($string, $this->connectionID) . "'"; + return "'" . $this->connectionID->real_escape_string($string) . "'"; } /** @@ -838,7 +741,7 @@ return 'NULL'; } - $string = mysql_real_escape_string($string, $this->connectionID); + $string = $this->connectionID->real_escape_string($string); // prevent double-escaping of MySQL wildcard symbols ("%" and "_") in case if they were already escaped return str_replace(Array ('\\\\%', '\\\\_'), Array ('\\%', '\\_'), $string); @@ -1047,14 +950,14 @@ * Initializes connection class with * db type to used in future * - * @param string $dbType - * @param string $errorHandler + * @param string $db_type + * @param string $error_handler * @param int $server_index * @access public */ - public function __construct($dbType, $errorHandler = '', $server_index = 0) + public function __construct($db_type, $error_handler = '', $server_index = 0) { - parent::__construct($dbType, $errorHandler, $server_index); + parent::__construct($db_type, $error_handler, $server_index); $this->_profileSQLs = defined('DBG_SQL_PROFILE') && DBG_SQL_PROFILE; } @@ -1106,8 +1009,6 @@ $this->_queryCount++; $this->lastQuery = $sql; - $query_func = $this->getMetaFunction('query'); - // set 1st checkpoint: begin if ( $this->_profileSQLs ) { $queryID = $debugger->generateID(); @@ -1116,19 +1017,18 @@ // set 1st checkpoint: end $this->setError(0, ''); // reset error - $this->queryID = $query_func($sql, $this->connectionID); + $this->queryID = $this->connectionID->query($sql); - if ( is_resource($this->queryID) ) { + if ( is_object($this->queryID) ) { $ret = Array (); - $fetch_func = $this->getMetaFunction('fetch_assoc'); if ( isset($key_field) ) { - while (($row = $fetch_func($this->queryID))) { + while ( $row = $this->queryID->fetch_assoc() ) { $ret[$row[$key_field]] = $row; } } else { - while (($row = $fetch_func($this->queryID))) { + while ( $row = $this->queryID->fetch_assoc() ) { $ret[] = $row; } } @@ -1188,8 +1088,6 @@ $this->_queryCount++; $this->lastQuery = $sql; - $query_func = $this->getMetaFunction('query'); - // set 1st checkpoint: begin if ( $this->_profileSQLs ) { $queryID = $debugger->generateID(); @@ -1198,9 +1096,9 @@ // set 1st checkpoint: end $this->setError(0, ''); // reset error - $this->queryID = $query_func($sql, $this->connectionID); + $this->queryID = $this->connectionID->query($sql); - if ( is_resource($this->queryID) ) { + if ( is_object($this->queryID) ) { $ret = new $iterator_class($this->queryID, $key_field); /* @var $ret kMySQLQuery */ @@ -1248,7 +1146,7 @@ /** * Query resource * - * @var resource + * @var mysqli_result * @access protected */ protected $result; @@ -1280,15 +1178,15 @@ /** * Creates new instance of a class * - * @param resource $result + * @param mysqli_result $result * @param null|string $key_field */ - public function __construct($result, $key_field = null) + public function __construct(mysqli_result $result, $key_field = null) { $this->result = $result; $this->keyField = $key_field; - $this->rowCount = mysql_num_rows($this->result); + $this->rowCount = $this->result->num_rows; $this->rewind(); } @@ -1392,9 +1290,9 @@ $this->position = $position; if ( $this->valid() ) { - mysql_data_seek($this->result, $this->position); + $this->result->data_seek($this->position); - $this->rowData = mysql_fetch_assoc($this->result); + $this->rowData = $this->result->fetch_assoc(); } /*if ( !$this->valid() ) { @@ -1423,7 +1321,7 @@ */ public function close() { - mysql_free_result($this->result); + $this->result->free(); unset($this->result); } Index: branches/5.2.x/core/kernel/utility/temp_handler.php =================================================================== diff -u -N -r15856 -r16407 --- branches/5.2.x/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 15856) +++ branches/5.2.x/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 16407) @@ -1,6 +1,6 @@ debugMode = $this->Application->isDebugMode(); - $connection->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB, true); + $connection->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB); } return $connection; @@ -1054,4 +1054,4 @@ return true; } -} \ No newline at end of file +} Index: branches/5.2.x/index.php =================================================================== diff -u -N -r16406 -r16407 --- branches/5.2.x/index.php (.../index.php) (revision 16406) +++ branches/5.2.x/index.php (.../index.php) (revision 16407) @@ -1,6 +1,6 @@ 'MySQL', /*'mssql' => 'MS-SQL Server', 'pgsql' => 'pgSQL'*/); + $options = Array ('mysqli' => 'MySQL', /*'mssql' => 'MS-SQL Server', 'pgsql' => 'pgSQL'*/); $option_tpl = ''."\n"; foreach ($options as $option_key => $option_title) { Index: branches/5.2.x/core/kernel/db/db_load_balancer.php =================================================================== diff -u -N -r15552 -r16407 --- branches/5.2.x/core/kernel/db/db_load_balancer.php (.../db_load_balancer.php) (revision 15552) +++ branches/5.2.x/core/kernel/db/db_load_balancer.php (.../db_load_balancer.php) (revision 16407) @@ -1,6 +1,6 @@ dbType = $dbType; - $this->errorHandler = $errorHandler; + $this->dbType = $db_type; + $this->errorHandler = $error_handler; $this->DBClusterTimeout *= 1e6; // convert to milliseconds } @@ -480,7 +480,7 @@ /* @var $db kDBConnection */ $db->debugMode = $debug_mode; - $db->Connect($server['DBHost'], $server['DBUser'], $server['DBUserPassword'], $this->servers[0]['DBName'], true, !$is_master); + $db->Connect($server['DBHost'], $server['DBUser'], $server['DBUserPassword'], $this->servers[0]['DBName'], !$is_master); return $db; }