// Fix tryToConnect methods for DB
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8386 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+15
-35
@@ -136,22 +136,6 @@ abstract class DbCore
|
|||||||
*/
|
*/
|
||||||
abstract public function getNumberError();
|
abstract public function getNumberError();
|
||||||
|
|
||||||
/**
|
|
||||||
* Try a connection to te database
|
|
||||||
*
|
|
||||||
* @param string $newDbLink
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
abstract public function tryConnection($newDbLink = true);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to change encoding on a database
|
|
||||||
*
|
|
||||||
* @param string $encoding
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
abstract public function tryEncoding($encoding = 'UTF8');
|
|
||||||
|
|
||||||
/* do not remove, useful for some modules */
|
/* do not remove, useful for some modules */
|
||||||
abstract public function set_db($db_name);
|
abstract public function set_db($db_name);
|
||||||
|
|
||||||
@@ -175,27 +159,25 @@ abstract class DbCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset(self::$_instance[$idServer]))
|
if (!isset(self::$_instance[$idServer]))
|
||||||
self::$_instance[$idServer] = Db::factory(self::$_servers[$idServer]['server'], self::$_servers[$idServer]['user'], self::$_servers[$idServer]['password'], self::$_servers[$idServer]['database']);
|
{
|
||||||
|
$class = Db::getClass();
|
||||||
|
self::$_instance[$idServer] = new $class(self::$_servers[$idServer]['server'], self::$_servers[$idServer]['user'], self::$_servers[$idServer]['password'], self::$_servers[$idServer]['database']);
|
||||||
|
}
|
||||||
|
|
||||||
return self::$_instance[$idServer];
|
return self::$_instance[$idServer];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get child layer class instance
|
* Get child layer class
|
||||||
*
|
*
|
||||||
* @param string $server Server address
|
* @return string
|
||||||
* @param string $user User login
|
|
||||||
* @param string $password User password
|
|
||||||
* @param string $database Database name
|
|
||||||
* @param bool $connect If false, don't connect in constructor
|
|
||||||
* @return Db
|
|
||||||
*/
|
*/
|
||||||
public static function factory($server, $user, $password, $database, $connect = true)
|
public static function getClass()
|
||||||
{
|
{
|
||||||
$class = 'MySQL';
|
$class = 'MySQL';
|
||||||
if (class_exists('mysqli', false))
|
if (class_exists('mysqli', false))
|
||||||
$class = 'DbMySQLi';
|
$class = 'DbMySQLi';
|
||||||
return new $class($server, $user, $password, $database, $connect);
|
return $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -505,27 +487,25 @@ abstract class DbCore
|
|||||||
* @param string $user Login for database connection
|
* @param string $user Login for database connection
|
||||||
* @param string $pwd Password for database connection
|
* @param string $pwd Password for database connection
|
||||||
* @param string $db Database name
|
* @param string $db Database name
|
||||||
|
* @param bool $newDbLink
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
static public function checkConnection($server, $user, $pwd, $db)
|
static public function checkConnection($server, $user, $pwd, $db, $newDbLink = true)
|
||||||
{
|
{
|
||||||
return Db::factory($server, $user, $pwd, $db, false)->tryConnection();
|
return call_user_func_array(array(Db::getClass(), 'tryToConnect'), array($server, $user, $pwd, $db, $newDbLink));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try a connection to te database
|
* Try a connection to te database
|
||||||
*
|
*
|
||||||
* @param string $server Server address
|
* @param string $server Server address
|
||||||
* @param string $user Login for database connection
|
* @param string $user Login for database connection
|
||||||
* @param string $pwd Password for database connection
|
* @param string $pwd Password for database connection
|
||||||
* @param string $db Database name
|
|
||||||
* @param string $newDbLink Database name
|
|
||||||
* @return int
|
* @return int
|
||||||
* @todo remake with static
|
|
||||||
*/
|
*/
|
||||||
static public function checkEncoding($server, $user, $pwd, $encoding = 'UTF8')
|
static public function checkEncoding($server, $user, $pwd)
|
||||||
{
|
{
|
||||||
return Db::factory($server, $user, $pwd, '', false)->tryEncoding($encoding);
|
return call_user_func_array(array(Db::getClass(), 'tryToConnect'), array($server, $user, $pwd));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-38
@@ -134,54 +134,19 @@ class DbMySQLiCore extends Db
|
|||||||
{
|
{
|
||||||
return $this->_link->query('USE '.pSQL($db_name));
|
return $this->_link->query('USE '.pSQL($db_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see DbCore::tryConnection()
|
|
||||||
*/
|
|
||||||
public function tryConnection($newDbLink = true)
|
|
||||||
{
|
|
||||||
$link = @new mysqli($this->_server, $this->_user, $this->_password, $this->_database);
|
|
||||||
|
|
||||||
// Do not use object way for error because this work bad before PHP 5.2.9
|
|
||||||
if (mysqli_connect_error())
|
|
||||||
return 1;
|
|
||||||
$link->close();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see DbCore::tryEncoding()
|
|
||||||
*/
|
|
||||||
public function tryEncoding($encoding = 'UTF8')
|
|
||||||
{
|
|
||||||
$link = @new mysqli($this->_server, $this->_user, $this->_password, $this->_database);
|
|
||||||
$ret = $link->query("SET NAMES '".pSQL($encoding)."'");
|
|
||||||
$link->close();
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated since 1.5.0
|
|
||||||
*/
|
|
||||||
static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true)
|
static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true)
|
||||||
{
|
{
|
||||||
Tools::displayAsDeprecated();
|
$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 1;
|
||||||
$link->close();
|
$link->close();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated since 1.5.0
|
|
||||||
*/
|
|
||||||
static public function tryUTF8($server, $user, $pwd)
|
static public function tryUTF8($server, $user, $pwd)
|
||||||
{
|
{
|
||||||
Tools::displayAsDeprecated();
|
$link = @new mysqli($server, $user, $pwd, $db);
|
||||||
|
|
||||||
$link = new mysqli($server, $user, $pwd, $db);
|
|
||||||
$ret = $link->query("SET NAMES 'UTF8'");
|
$ret = $link->query("SET NAMES 'UTF8'");
|
||||||
$link->close();
|
$link->close();
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|||||||
@@ -136,36 +136,6 @@ class MySQLCore extends Db
|
|||||||
return mysql_select_db($db_name, $this->_link);
|
return mysql_select_db($db_name, $this->_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see DbCore::tryConnection()
|
|
||||||
*/
|
|
||||||
public function tryConnection($newDbLink = true)
|
|
||||||
{
|
|
||||||
if (!$link = @mysql_connect($server, $user, $pwd, $newDbLink))
|
|
||||||
return 1;
|
|
||||||
if (!@mysql_select_db($db, $link))
|
|
||||||
return 2;
|
|
||||||
@mysql_close($link);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see DbCore::tryEncoding()
|
|
||||||
*/
|
|
||||||
public function tryEncoding($encoding = 'UTF8')
|
|
||||||
{
|
|
||||||
$link = @mysql_connect($server, $user, $pwd);
|
|
||||||
if (!mysql_query('SET NAMES \''.pSQL($encoding).'\'', $link))
|
|
||||||
$ret = false;
|
|
||||||
else
|
|
||||||
$ret = true;
|
|
||||||
@mysql_close($link);
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated since 1.5.0
|
|
||||||
*/
|
|
||||||
public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true)
|
public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true)
|
||||||
{
|
{
|
||||||
if (!$link = @mysql_connect($server, $user, $pwd, $newDbLink))
|
if (!$link = @mysql_connect($server, $user, $pwd, $newDbLink))
|
||||||
@@ -176,9 +146,6 @@ class MySQLCore extends Db
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated since 1.5.0
|
|
||||||
*/
|
|
||||||
static public function tryUTF8($server, $user, $pwd)
|
static public function tryUTF8($server, $user, $pwd)
|
||||||
{
|
{
|
||||||
$link = @mysql_connect($server, $user, $pwd);
|
$link = @mysql_connect($server, $user, $pwd);
|
||||||
|
|||||||
Reference in New Issue
Block a user