// Check if at least one table with same prefix already exists in new installer
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12194 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -601,20 +601,47 @@ abstract class DbCore
|
||||
return call_user_func_array(array(Db::getClass(), 'tryUTF8'), array($server, $user, $pwd));
|
||||
}
|
||||
|
||||
/**
|
||||
* Try a connection to the database and check if at least one table with same prefix exists
|
||||
*
|
||||
* @param string $server Server address
|
||||
* @param string $user Login for database connection
|
||||
* @param string $pwd Password for database connection
|
||||
* @param string $db Database name
|
||||
* @param string $prefix Tables prefix
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasTableWithSamePrefix($server, $user, $pwd, $db, $prefix)
|
||||
{
|
||||
return call_user_func_array(array(Db::getClass(), 'hasTableWithSamePrefix'), array($server, $user, $pwd, $db, $prefix));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 1.5.0
|
||||
*/
|
||||
public static function s($sql, $use_cache = true)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
return Db::getInstance()->executeS($sql, true, $use_cache);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 1.5.0
|
||||
*/
|
||||
public static function ps($sql, $use_cache = 1)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
$ret = Db::s($sql, $use_cache);
|
||||
p($ret);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 1.5.0
|
||||
*/
|
||||
public static function ds($sql, $use_cache = 1)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
Db::s($sql, $use_cache);
|
||||
die();
|
||||
}
|
||||
|
||||
@@ -138,6 +138,23 @@ class DbMySQLiCore extends Db
|
||||
return $this->link->query('USE '.pSQL($db_name));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Db::hasTableWithSamePrefix()
|
||||
*/
|
||||
public static function hasTableWithSamePrefix($server, $user, $pwd, $db, $prefix)
|
||||
{
|
||||
$link = @new mysqli($server, $user, $pwd, $db);
|
||||
if (mysqli_connect_error())
|
||||
return false;
|
||||
|
||||
$sql = 'SHOW TABLES LIKE \''.$prefix.'%\'';
|
||||
$result = $link->query($sql);
|
||||
return (bool)$result->fetch_assoc();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Db::checkConnection()
|
||||
*/
|
||||
static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null)
|
||||
{
|
||||
$link = @new mysqli($server, $user, $pwd, $db);
|
||||
@@ -158,6 +175,9 @@ class DbMySQLiCore extends Db
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Db::checkEncoding()
|
||||
*/
|
||||
static public function tryUTF8($server, $user, $pwd)
|
||||
{
|
||||
$link = @new mysqli($server, $user, $pwd, $db);
|
||||
|
||||
+21
-2
@@ -149,7 +149,26 @@ class DbPDOCore extends Db
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DbCore::tryToConnect()
|
||||
* @see Db::hasTableWithSamePrefix()
|
||||
*/
|
||||
public static function hasTableWithSamePrefix($server, $user, $pwd, $db, $prefix)
|
||||
{
|
||||
try
|
||||
{
|
||||
$link = @new PDO('mysql:dbname='.$db.';host='.$server, $user, $pwd);
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$sql = 'SHOW TABLES LIKE \''.$prefix.'%\'';
|
||||
$result = $link->query($sql);
|
||||
return (bool)$result->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Db::checkConnection()
|
||||
*/
|
||||
static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null)
|
||||
{
|
||||
@@ -177,7 +196,7 @@ class DbPDOCore extends Db
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DbCore::tryUTF8()
|
||||
* @see Db::checkEncoding()
|
||||
*/
|
||||
static public function tryUTF8($server, $user, $pwd)
|
||||
{
|
||||
|
||||
@@ -136,6 +136,24 @@ class MySQLCore extends Db
|
||||
return mysql_select_db($db_name, $this->link);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Db::hasTableWithSamePrefix()
|
||||
*/
|
||||
public static function hasTableWithSamePrefix($server, $user, $pwd, $db, $prefix)
|
||||
{
|
||||
if (!$link = @mysql_connect($server, $user, $pwd, true))
|
||||
return false;
|
||||
if (!@mysql_select_db($db, $link))
|
||||
return false;
|
||||
|
||||
$sql = 'SHOW TABLES LIKE \''.$prefix.'%\'';
|
||||
$result = mysql_query($sql);
|
||||
return (bool)@mysql_fetch_assoc($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Db::checkConnection()
|
||||
*/
|
||||
public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null)
|
||||
{
|
||||
if (!$link = @mysql_connect($server, $user, $pwd, $newDbLink))
|
||||
@@ -157,6 +175,9 @@ class MySQLCore extends Db
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Db::checkEncoding()
|
||||
*/
|
||||
static public function tryUTF8($server, $user, $pwd)
|
||||
{
|
||||
$link = @mysql_connect($server, $user, $pwd);
|
||||
|
||||
@@ -66,6 +66,10 @@ class InstallModelDatabase extends InstallAbstractModel
|
||||
case 0:
|
||||
if (!Db::checkEncoding($server, $login, $password))
|
||||
$errors[] = $this->language->l('Cannot convert database data to utf-8');
|
||||
|
||||
// Check if a table with same prefix already exists
|
||||
if (Db::hasTableWithSamePrefix($server, $login, $password, $database, $prefix))
|
||||
$errors[] = $this->language->l('At least one table with same prefix was already found, please change your prefix or drop your database');
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
Reference in New Issue
Block a user