[*] Installer : added timout to sql connection
This commit is contained in:
+2
-2
@@ -637,9 +637,9 @@ abstract class DbCore
|
||||
* @param bool $engine
|
||||
* @return int
|
||||
*/
|
||||
public static function checkConnection($server, $user, $pwd, $db, $new_db_link = true, $engine = null)
|
||||
public static function checkConnection($server, $user, $pwd, $db, $new_db_link = true, $engine = null, $timeout = 5)
|
||||
{
|
||||
return call_user_func_array(array(Db::getClass(), 'tryToConnect'), array($server, $user, $pwd, $db, $new_db_link, $engine));
|
||||
return call_user_func_array(array(Db::getClass(), 'tryToConnect'), array($server, $user, $pwd, $db, $new_db_link, $engine, $timeout));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -161,10 +161,16 @@ class DbMySQLiCore extends Db
|
||||
/**
|
||||
* @see Db::checkConnection()
|
||||
*/
|
||||
static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null)
|
||||
public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null, $timeout = 5)
|
||||
{
|
||||
$link = @new mysqli($server, $user, $pwd, $db);
|
||||
if (mysqli_connect_error())
|
||||
$link = mysqli_init();
|
||||
if (!$link)
|
||||
return -1;
|
||||
|
||||
if (!$link->options(MYSQLI_OPT_CONNECT_TIMEOUT, $timeout))
|
||||
return 1;
|
||||
|
||||
if (!$link->real_connect($server, $user, $pwd, $db);
|
||||
return (mysqli_connect_errno() == 1049) ? 2 : 1;
|
||||
|
||||
if (strtolower($engine) == 'innodb')
|
||||
|
||||
@@ -179,11 +179,11 @@ class DbPDOCore extends Db
|
||||
/**
|
||||
* @see Db::checkConnection()
|
||||
*/
|
||||
static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null)
|
||||
public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null, $timeout = 5)
|
||||
{
|
||||
try
|
||||
{
|
||||
$link = @new PDO('mysql:dbname='.$db.';host='.$server, $user, $pwd);
|
||||
$link = @new PDO('mysql:dbname='.$db.';host='.$server, $user, $pwd, array(PDO::ATTR_TIMEOUT => $timeout));
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
|
||||
@@ -156,6 +156,7 @@ class MySQLCore extends Db
|
||||
*/
|
||||
public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null)
|
||||
{
|
||||
ini_set('mysql.connect_timeout', $timeout);
|
||||
if (!$link = @mysql_connect($server, $user, $pwd, $newDbLink))
|
||||
return 1;
|
||||
if (!@mysql_select_db($db, $link))
|
||||
|
||||
Reference in New Issue
Block a user