[+] Classes: add PDO support if extension is activated
[*] Classes: add engine check (innodb)
This commit is contained in:
1 parent
f8fb147034
commit
cf4db864d3
5 files changed
+56
-16
No files matched your search
@@ -44,12 +44,17 @@ class ConfigurationTestCore
|
|||||||
|
|
||||||
public static function test_phpversion()
|
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()
|
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()
|
public static function test_magicquotes()
|
||||||
|
|||||||
+5
-3
@@ -180,8 +180,10 @@ abstract class DbCore
|
|||||||
public static function getClass()
|
public static function getClass()
|
||||||
{
|
{
|
||||||
$class = 'MySQL';
|
$class = 'MySQL';
|
||||||
if (0&&class_exists('mysqli', false))
|
if (extension_loaded('mysqli'))
|
||||||
$class = 'DbMySQLi';
|
$class = 'DbMySQLi';
|
||||||
|
else if (extension_loaded('pdo_mysql'))
|
||||||
|
$class = 'DbPDO';
|
||||||
return $class;
|
return $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,9 +527,9 @@ abstract class DbCore
|
|||||||
* @param bool $newDbLink
|
* @param bool $newDbLink
|
||||||
* @return int
|
* @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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+13
-2
@@ -138,11 +138,22 @@ class DbMySQLiCore extends Db
|
|||||||
return $this->link->query('USE '.pSQL($db_name));
|
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);
|
$link = @new mysqli($server, $user, $pwd, $db);
|
||||||
if (mysqli_connect_error())
|
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();
|
$link->close();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-8
@@ -84,7 +84,7 @@ class DbPDOCore extends Db
|
|||||||
*/
|
*/
|
||||||
protected function _numRows($result)
|
protected function _numRows($result)
|
||||||
{
|
{
|
||||||
return $result->rowCount();;
|
return $result->rowCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,17 +151,28 @@ class DbPDOCore extends Db
|
|||||||
/**
|
/**
|
||||||
* @see DbCore::tryToConnect()
|
* @see DbCore::tryToConnect()
|
||||||
*/
|
*/
|
||||||
static public function tryToConnect($server, $user, $pwd, $db)
|
static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$test = new PDO('mysql:dbname='.$db.';host='.$server, $user, $pwd);
|
$link = @new PDO('mysql:dbname='.$db.';host='.$server, $user, $pwd);
|
||||||
}
|
}
|
||||||
catch (PDOException $e)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,14 +183,14 @@ class DbPDOCore extends Db
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$test = new PDO('mysql:dbname='.$db.';host='.$server, $user, $pwd);
|
$link = new PDO('mysql:host='.$server, $user, $pwd);
|
||||||
}
|
}
|
||||||
catch (PDOException $e)
|
catch (PDOException $e)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$result = $test->exec('SET NAMES \'utf8\'');
|
$result = $link->exec('SET NAMES \'utf8\'');
|
||||||
unset($test);
|
unset($link);
|
||||||
|
|
||||||
return ($result === false) ? false : true;
|
return ($result === false) ? false : true;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-1
@@ -136,12 +136,23 @@ class MySQLCore extends Db
|
|||||||
return mysql_select_db($db_name, $this->link);
|
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))
|
if (!$link = @mysql_connect($server, $user, $pwd, $newDbLink))
|
||||||
return 1;
|
return 1;
|
||||||
if (!@mysql_select_db($db, $link))
|
if (!@mysql_select_db($db, $link))
|
||||||
return 2;
|
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);
|
@mysql_close($link);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user