diff --git a/classes/ConfigurationTest.php b/classes/ConfigurationTest.php index 40bd202e6..ea3343811 100644 --- a/classes/ConfigurationTest.php +++ b/classes/ConfigurationTest.php @@ -44,12 +44,17 @@ class ConfigurationTestCore public static function test_phpversion() { - return version_compare(substr(phpversion(), 0, 3), '5.1', '>='); + return version_compare(substr(phpversion(), 0, 5), '5.1.0', '>='); } public static function test_mysql_support() { - return function_exists('mysql_connect'); + return extension_loaded('mysql') || extension_loaded('mysqli') || extension_loaded('pdo_mysql'); + } + + public static function test_pdo_mysql() + { + return extension_loaded('pdo_mysql'); } public static function test_magicquotes() diff --git a/classes/db/Db.php b/classes/db/Db.php index 78e2a865d..5ab8976ea 100644 --- a/classes/db/Db.php +++ b/classes/db/Db.php @@ -180,8 +180,10 @@ abstract class DbCore public static function getClass() { $class = 'MySQL'; - if (0&&class_exists('mysqli', false)) + if (extension_loaded('mysqli')) $class = 'DbMySQLi'; + else if (extension_loaded('pdo_mysql')) + $class = 'DbPDO'; return $class; } @@ -525,9 +527,9 @@ abstract class DbCore * @param bool $newDbLink * @return int */ - public static function checkConnection($server, $user, $pwd, $db, $new_db_link = true) + public static function checkConnection($server, $user, $pwd, $db, $new_db_link = true, $engine = null) { - return call_user_func_array(array(Db::getClass(), 'tryToConnect'), array($server, $user, $pwd, $db, $new_db_link)); + return call_user_func_array(array(Db::getClass(), 'tryToConnect'), array($server, $user, $pwd, $db, $new_db_link, $engine)); } /** diff --git a/classes/db/DbMySQLi.php b/classes/db/DbMySQLi.php index aab0f9cd1..d0765939c 100644 --- a/classes/db/DbMySQLi.php +++ b/classes/db/DbMySQLi.php @@ -138,11 +138,22 @@ class DbMySQLiCore extends Db return $this->link->query('USE '.pSQL($db_name)); } - static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true) + static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null) { $link = @new mysqli($server, $user, $pwd, $db); if (mysqli_connect_error()) - return 1; + return (mysqli_connect_errno() == 1049) ? 2 : 1; + + if (strtolower($engine) == 'innodb') + { + $sql = 'SHOW VARIABLES WHERE Variable_name = \'have_innodb\''; + $result = $link->query($sql); + if (!$result) + return 4; + $row = $result->fetch_assoc(); + if (!$row || strtolower($row['Value']) != 'yes') + return 4; + } $link->close(); return 0; } diff --git a/classes/db/DbPDO.php b/classes/db/DbPDO.php index 19c5d9a96..0411579a6 100644 --- a/classes/db/DbPDO.php +++ b/classes/db/DbPDO.php @@ -84,7 +84,7 @@ class DbPDOCore extends Db */ protected function _numRows($result) { - return $result->rowCount();; + return $result->rowCount(); } /** @@ -151,17 +151,28 @@ class DbPDOCore extends Db /** * @see DbCore::tryToConnect() */ - static public function tryToConnect($server, $user, $pwd, $db) + static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null) { try { - $test = new PDO('mysql:dbname='.$db.';host='.$server, $user, $pwd); + $link = @new PDO('mysql:dbname='.$db.';host='.$server, $user, $pwd); } catch (PDOException $e) { - return 1; + return ($e->getCode() == 1049) ? 2 : 1; } - unset($test); + + if (strtolower($engine) == 'innodb') + { + $sql = 'SHOW VARIABLES WHERE Variable_name = \'have_innodb\''; + $result = $link->query($sql); + if (!$result) + return 4; + $row = $result->fetch(); + if (!$row || strtolower($row['Value']) != 'yes') + return 4; + } + unset($link); return 0; } @@ -172,14 +183,14 @@ class DbPDOCore extends Db { try { - $test = new PDO('mysql:dbname='.$db.';host='.$server, $user, $pwd); + $link = new PDO('mysql:host='.$server, $user, $pwd); } catch (PDOException $e) { return false; } - $result = $test->exec('SET NAMES \'utf8\''); - unset($test); + $result = $link->exec('SET NAMES \'utf8\''); + unset($link); return ($result === false) ? false : true; } diff --git a/classes/db/MySQL.php b/classes/db/MySQL.php index 8fac5eabd..75e14cdd1 100644 --- a/classes/db/MySQL.php +++ b/classes/db/MySQL.php @@ -136,12 +136,23 @@ class MySQLCore extends Db return mysql_select_db($db_name, $this->link); } - public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true) + public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null) { if (!$link = @mysql_connect($server, $user, $pwd, $newDbLink)) return 1; if (!@mysql_select_db($db, $link)) return 2; + + if (strtolower($engine) == 'innodb') + { + $sql = 'SHOW VARIABLES WHERE Variable_name = \'have_innodb\''; + $result = mysql_query($sql); + if (!$result) + return 4; + $row = mysql_fetch_assoc($result); + if (!$row || strtolower($row['Value']) != 'yes') + return 4; + } @mysql_close($link); return 0; }