Index: core/kernel/db/db_load_balancer.php =================================================================== --- core/kernel/db/db_load_balancer.php (revision 15930) +++ core/kernel/db/db_load_balancer.php (revision 15931) @@ -22,7 +22,7 @@ * @var string * @access protected */ - protected $dbType = 'mysql'; + protected $dbType = 'mysqli'; /** * Function to handle sql errors @@ -115,15 +115,15 @@ /** * Creates new instance of load balancer class * - * @param string $dbType - * @param Array|string $errorHandler + * @param string $db_type + * @param Array|string $error_handler */ - function __construct($dbType, $errorHandler = '') + function __construct($db_type, $error_handler = '') { parent::__construct(); - $this->dbType = $dbType; - $this->errorHandler = $errorHandler; + $this->dbType = $db_type; + $this->errorHandler = $error_handler; $this->DBClusterTimeout *= 1e6; // convert to milliseconds } @@ -493,7 +493,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; } Index: core/kernel/db/db_connection.php =================================================================== --- core/kernel/db/db_connection.php (revision 15930) +++ core/kernel/db/db_connection.php (revision 15931) @@ -21,20 +21,12 @@ class kDBConnection extends kBase implements IDBConnection { /** - * Current database type - * - * @var string - * @access protected - */ - protected $dbType = 'mysql'; - - /** * Created connection handle * - * @var resource + * @var mysqli * @access protected */ - protected $connectionID = null; + protected $connectionID; /** * Remembers, that database connection was opened successfully @@ -63,20 +55,12 @@ /** * Handle of currently processed recordset * - * @var resource + * @var mysqli_result * @access protected */ protected $queryID = null; /** - * DB type specific function mappings - * - * @var Array - * @access protected - */ - protected $metaFunctions = Array (); - - /** * Function to handle sql errors * * @var Array|string @@ -162,27 +146,25 @@ * 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) { if ( class_exists('kApplication') ) { // prevents "Fatal Error" on 2nd installation step (when database is empty) parent::__construct(); } - $this->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); @@ -213,88 +195,43 @@ } /** - * 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. * * @param string $host * @param string $user * @param string $pass * @param string $db - * @param bool $force_new * @param bool $retry * * @return bool * @access public * @throws RuntimeException When connection failed. */ - 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 ) { @@ -346,17 +283,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 @@ -366,7 +301,7 @@ $this->connectionParams['user'], $this->connectionParams['pass'], $this->connectionParams['db'], - $force_new, true + true ); if ( $connected ) { @@ -393,15 +328,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); @@ -414,11 +346,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); @@ -482,21 +413,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. * * @param string $sql @@ -602,26 +518,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; } } @@ -671,16 +584,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 */ @@ -716,9 +627,7 @@ */ public function Destroy() { - $free_func = $this->getMetaFunction('free_result'); - $free_func($this->queryID); - + $this->queryID->free(); unset($this->queryID); } @@ -744,8 +653,7 @@ */ public function getInsertID() { - $func = $this->getMetaFunction('insert_id'); - return $func($this->connectionID); + return $this->connectionID->insert_id; } /** @@ -756,8 +664,7 @@ */ public function getAffectedRows() { - $func = $this->getMetaFunction('affected_rows'); - return $func($this->connectionID); + return $this->connectionID->affected_rows; } /** @@ -774,11 +681,7 @@ return ''; } - switch ( $this->dbType ) { - default: - return 'LIMIT ' . $offset . ',' . $rows; - break; - } + return 'LIMIT ' . $offset . ',' . $rows; } /** @@ -798,7 +701,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) . "'"; } /** @@ -826,7 +729,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); @@ -1035,14 +938,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; } @@ -1092,8 +995,6 @@ $this->_queryCount++; $this->lastQuery = $sql; - $query_func = $this->getMetaFunction('query'); - // set 1st checkpoint: begin if ( $this->_profileSQLs ) { $queryID = $debugger->generateID(); @@ -1102,19 +1003,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; } } @@ -1175,8 +1075,6 @@ $this->_queryCount++; $this->lastQuery = $sql; - $query_func = $this->getMetaFunction('query'); - // set 1st checkpoint: begin if ( $this->_profileSQLs ) { $queryID = $debugger->generateID(); @@ -1185,9 +1083,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 */ @@ -1235,7 +1133,7 @@ /** * Query resource * - * @var resource + * @var mysqli_result * @access protected */ protected $result; @@ -1267,15 +1165,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(); } @@ -1379,9 +1277,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() ) { @@ -1410,7 +1308,7 @@ */ public function close() { - mysql_free_result($this->result); + $this->result->free(); unset($this->result); } Index: core/kernel/startup.php =================================================================== --- core/kernel/startup.php (revision 15930) +++ core/kernel/startup.php (revision 15931) @@ -90,8 +90,8 @@ define('SQL_DB', $vars['DBName']); if (isset($vars['DBCollation']) && isset($vars['DBCharset'])) { - define('SQL_COLLATION', $vars['DBCollation']); - define('SQL_CHARSET', $vars['DBCharset']); + define('SQL_COLLATION', $vars['DBCollation']); // utf8_general_ci + define('SQL_CHARSET', $vars['DBCharset']); // utf8 } define('TABLE_PREFIX', $vars['TablePrefix']); Index: core/kernel/utility/temp_handler.php =================================================================== --- core/kernel/utility/temp_handler.php (revision 15930) +++ core/kernel/utility/temp_handler.php (revision 15931) @@ -210,7 +210,7 @@ /* @var $connection kDBConnection */ $connection->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; Index: core/install/step_templates/db_reconfig.tpl =================================================================== --- core/install/step_templates/db_reconfig.tpl (revision 15930) +++ core/install/step_templates/db_reconfig.tpl (revision 15931) @@ -3,7 +3,7 @@ '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) { @@ -67,7 +67,7 @@ GetVar('preset') != 'already_installed') { ?> - + Use existing In-Portal installation in this Database: Index: core/install/prerequisites.php =================================================================== --- core/install/prerequisites.php (revision 15930) +++ core/install/prerequisites.php (revision 15931) @@ -142,7 +142,7 @@ } $ret['jpeg'] = function_exists('imagecreatefromjpeg'); - $ret['mysql'] = function_exists('mysql_connect'); + $ret['mysql'] = function_exists('mysqli_connect'); $ret['json'] = function_exists('json_encode'); $output = shell_exec('java -version 2>&1');