// Remove bad _SQL_USE_SLAVE_ uses + normalize Db->executeS(), Db->execute() and Db->numRows() names
This commit is contained in:
+83
-78
@@ -31,25 +31,25 @@ if (file_exists(dirname(__FILE__).'/../config/settings.inc.php'))
|
||||
abstract class DbCore
|
||||
{
|
||||
/** @var string Server (eg. localhost) */
|
||||
protected $_server;
|
||||
protected $server;
|
||||
|
||||
/** @var string Database user (eg. root) */
|
||||
protected $_user;
|
||||
protected $user;
|
||||
|
||||
/** @var string Database password (eg. can be empty !) */
|
||||
protected $_password;
|
||||
protected $password;
|
||||
|
||||
/** @var string Database name */
|
||||
protected $_database;
|
||||
protected $database;
|
||||
|
||||
/** @var mixed Ressource link */
|
||||
protected $_link;
|
||||
protected $link;
|
||||
|
||||
/** @var mixed SQL cached result */
|
||||
protected $_result;
|
||||
protected $result;
|
||||
|
||||
/** @var array List of DB instance */
|
||||
protected static $_instance = array();
|
||||
protected static $instance = array();
|
||||
|
||||
/** @var array Object instance for singleton */
|
||||
protected static $_servers = array(
|
||||
@@ -64,14 +64,14 @@ abstract class DbCore
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_lastQuery;
|
||||
protected $last_query;
|
||||
|
||||
/**
|
||||
* Last cached query
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_lastCached;
|
||||
protected $last_cached;
|
||||
|
||||
/**
|
||||
* Open a connection
|
||||
@@ -149,22 +149,27 @@ abstract class DbCore
|
||||
{
|
||||
static $id = 0;
|
||||
|
||||
$nServers = sizeof(self::$_servers);
|
||||
if ($master || $nServers == 1)
|
||||
$idServer = 0;
|
||||
$total_servers = count(self::$_servers);
|
||||
if ($master || $total_servers == 1)
|
||||
$id_server = 0;
|
||||
else
|
||||
{
|
||||
$id++;
|
||||
$idServer = ($nServers > 2 && ($id % $nServers) != 0) ? $id : 1;
|
||||
$id_server = ($total_servers > 2 && ($id % $total_servers) != 0) ? $id : 1;
|
||||
}
|
||||
|
||||
if (!isset(self::$_instance[$idServer]))
|
||||
if (!isset(self::$instance[$id_server]))
|
||||
{
|
||||
$class = Db::getClass();
|
||||
self::$_instance[$idServer] = new $class(self::$_servers[$idServer]['server'], self::$_servers[$idServer]['user'], self::$_servers[$idServer]['password'], self::$_servers[$idServer]['database']);
|
||||
self::$instance[$id_server] = new $class(
|
||||
self::$_servers[$id_server]['server'],
|
||||
self::$_servers[$id_server]['user'],
|
||||
self::$_servers[$id_server]['password'],
|
||||
self::$_servers[$id_server]['database']
|
||||
);
|
||||
}
|
||||
|
||||
return self::$_instance[$idServer];
|
||||
return self::$instance[$id_server];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,11 +196,11 @@ abstract class DbCore
|
||||
*/
|
||||
public function __construct($server, $user, $password, $database, $connect = true)
|
||||
{
|
||||
$this->_server = $server;
|
||||
$this->_user = $user;
|
||||
$this->_password = $password;
|
||||
$this->_type = _DB_TYPE_;
|
||||
$this->_database = $database;
|
||||
$this->server = $server;
|
||||
$this->user = $user;
|
||||
$this->password = $password;
|
||||
$this->type = _DB_TYPE_;
|
||||
$this->database = $database;
|
||||
|
||||
if (!defined('_PS_DEBUG_SQL_'))
|
||||
define('_PS_DEBUG_SQL_', false);
|
||||
@@ -209,7 +214,7 @@ abstract class DbCore
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->_link)
|
||||
if ($this->link)
|
||||
$this->disconnect();
|
||||
}
|
||||
|
||||
@@ -221,10 +226,10 @@ abstract class DbCore
|
||||
* @param string $type INSERT or UPDATE
|
||||
* @param string $where WHERE clause, only for UPDATE (optional)
|
||||
* @param string $limit LIMIT clause (optional)
|
||||
* @param bool $useNull If true, replace empty strings and NULL by a NULL value
|
||||
* @param bool $use_null If true, replace empty strings and NULL by a NULL value
|
||||
* @return mixed|boolean SQL query result
|
||||
*/
|
||||
public function autoExecute($table, $data, $type, $where = false, $limit = false, $use_cache = 1, $useNull = false)
|
||||
public function autoExecute($table, $data, $type, $where = false, $limit = false, $use_cache = 1, $use_null = false)
|
||||
{
|
||||
if (!$data)
|
||||
return true;
|
||||
@@ -234,13 +239,13 @@ abstract class DbCore
|
||||
// Check if $data is a list of row
|
||||
if (!is_array(current($data)))
|
||||
$data = array($data);
|
||||
|
||||
|
||||
$keys = array();
|
||||
$values_stringified = array();
|
||||
foreach ($data as $row_data)
|
||||
{
|
||||
$values = array();
|
||||
foreach ($row_data AS $key => $value)
|
||||
foreach ($row_data as $key => $value)
|
||||
{
|
||||
if (isset($keys_stringified))
|
||||
{
|
||||
@@ -250,8 +255,8 @@ abstract class DbCore
|
||||
}
|
||||
else
|
||||
$keys[] = "`$key`";
|
||||
|
||||
$values[] = ($useNull && ($value === '' || is_null($value))) ? 'NULL' : "'$value'";
|
||||
|
||||
$values[] = ($use_null && ($value === '' || is_null($value))) ? 'NULL' : "'$value'";
|
||||
}
|
||||
$keys_stringified = implode(', ', $keys);
|
||||
$values_stringified[] = '('.implode(', ', $values).')';
|
||||
@@ -265,8 +270,8 @@ abstract class DbCore
|
||||
else if (strtoupper($type) == 'UPDATE')
|
||||
{
|
||||
$sql = 'UPDATE `'.$table.'` SET ';
|
||||
foreach ($data AS $key => $value)
|
||||
$sql .= ($useNull && ($value === '' || is_null($value))) ? "`$key` = NULL," : "`$key` = '$value',";
|
||||
foreach ($data as $key => $value)
|
||||
$sql .= ($use_null && ($value === '' || is_null($value))) ? "`$key` = NULL," : "`$key` = '$value',";
|
||||
$sql = rtrim($sql, ',');
|
||||
if ($where)
|
||||
$sql .= ' WHERE '.$where;
|
||||
@@ -321,10 +326,10 @@ abstract class DbCore
|
||||
*/
|
||||
public function delete($table, $where = false, $limit = false, $use_cache = 1)
|
||||
{
|
||||
$this->_result = false;
|
||||
$this->result = false;
|
||||
$sql = 'DELETE FROM `'.bqSQL($table).'`'.($where ? ' WHERE '.$where : '').($limit ? ' LIMIT '.(int)$limit : '');
|
||||
$res = $this->query($sql);
|
||||
if ($use_cache AND _PS_CACHE_ENABLED_)
|
||||
if ($use_cache && _PS_CACHE_ENABLED_)
|
||||
Cache::getInstance()->deleteQuery($sql);
|
||||
return $res;
|
||||
}
|
||||
@@ -336,13 +341,13 @@ abstract class DbCore
|
||||
* @param bool $use_cache
|
||||
* @return mixed
|
||||
*/
|
||||
public function Execute($sql, $use_cache = 1)
|
||||
public function execute($sql, $use_cache = 1)
|
||||
{
|
||||
$sql = (string)$sql;
|
||||
$this->_result = $this->query($sql);
|
||||
if ($use_cache AND _PS_CACHE_ENABLED_)
|
||||
$this->result = $this->query($sql);
|
||||
if ($use_cache && _PS_CACHE_ENABLED_)
|
||||
Cache::getInstance()->deleteQuery($sql);
|
||||
return $this->_result;
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,32 +358,32 @@ abstract class DbCore
|
||||
* @param int $use_cache if query has been already executed, use its result
|
||||
* @return array or result object
|
||||
*/
|
||||
public function ExecuteS($sql, $array = true, $use_cache = 1)
|
||||
public function executeS($sql, $array = true, $use_cache = 1)
|
||||
{
|
||||
$sql = (string)$sql;
|
||||
$this->_result = false;
|
||||
$this->_lastQuery = $sql;
|
||||
if ($use_cache AND _PS_CACHE_ENABLED_ && $array AND ($result = Cache::getInstance()->get(md5($sql))))
|
||||
$this->result = false;
|
||||
$this->last_query = $sql;
|
||||
if ($use_cache && _PS_CACHE_ENABLED_ && $array && ($result = Cache::getInstance()->get(md5($sql))))
|
||||
{
|
||||
$this->_lastCached = true;
|
||||
$this->last_cached = true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
$this->_result = $this->query($sql);
|
||||
if (!$this->_result)
|
||||
$this->result = $this->query($sql);
|
||||
if (!$this->result)
|
||||
return false;
|
||||
|
||||
$this->_lastCached = false;
|
||||
$this->last_cached = false;
|
||||
if (!$array)
|
||||
return $this->_result;
|
||||
return $this->result;
|
||||
|
||||
$resultArray = array();
|
||||
while ($row = $this->nextRow($this->_result))
|
||||
$resultArray[] = $row;
|
||||
$result_array = array();
|
||||
while ($row = $this->nextRow($this->result))
|
||||
$result_array[] = $row;
|
||||
|
||||
if ($use_cache AND _PS_CACHE_ENABLED_)
|
||||
Cache::getInstance()->setQuery($sql, $resultArray);
|
||||
return $resultArray;
|
||||
if ($use_cache && _PS_CACHE_ENABLED_)
|
||||
Cache::getInstance()->setQuery($sql, $result_array);
|
||||
return $result_array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,21 +398,21 @@ abstract class DbCore
|
||||
{
|
||||
$sql = (string)$sql;
|
||||
$sql .= ' LIMIT 1';
|
||||
$this->_result = false;
|
||||
$this->_lastQuery = $sql;
|
||||
$this->result = false;
|
||||
$this->last_query = $sql;
|
||||
if ($use_cache && _PS_CACHE_ENABLED_ && ($result = Cache::getInstance()->get(md5($sql))))
|
||||
{
|
||||
$this->_lastCached = true;
|
||||
$this->last_cached = true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
$this->_result = $this->query($sql);
|
||||
if (!$this->_result)
|
||||
$this->result = $this->query($sql);
|
||||
if (!$this->result)
|
||||
return false;
|
||||
|
||||
$this->_lastCached = false;
|
||||
$result = $this->nextRow($this->_result);
|
||||
if ($use_cache AND _PS_CACHE_ENABLED_)
|
||||
$this->last_cached = false;
|
||||
$result = $this->nextRow($this->result);
|
||||
if ($use_cache && _PS_CACHE_ENABLED_)
|
||||
Cache::getInstance()->setQuery($sql, $result);
|
||||
return $result;
|
||||
}
|
||||
@@ -432,17 +437,17 @@ abstract class DbCore
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function NumRows()
|
||||
public function numRows()
|
||||
{
|
||||
if (!$this->_lastCached && $this->_result)
|
||||
if (!$this->last_cached && $this->result)
|
||||
{
|
||||
$nrows = $this->_numRows($this->_result);
|
||||
$nrows = $this->_numRows($this->result);
|
||||
if (_PS_CACHE_ENABLED_)
|
||||
Cache::getInstance()->setNumRows(md5($this->_lastQuery), $nrows);
|
||||
Cache::getInstance()->setNumRows(md5($this->last_query), $nrows);
|
||||
return $nrows;
|
||||
}
|
||||
else if (_PS_CACHE_ENABLED_ AND $this->_lastCached)
|
||||
return Cache::getInstance()->getNumRows(md5($this->_lastQuery));
|
||||
else if (_PS_CACHE_ENABLED_ && $this->last_cached)
|
||||
return Cache::getInstance()->getNumRows(md5($this->last_query));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -457,9 +462,9 @@ abstract class DbCore
|
||||
global $webservice_call;
|
||||
|
||||
$sql = (string)$sql;
|
||||
$this->_result = false;
|
||||
$this->result = false;
|
||||
$result = $this->query($sql);
|
||||
if ($use_cache AND _PS_CACHE_ENABLED_)
|
||||
if ($use_cache && _PS_CACHE_ENABLED_)
|
||||
Cache::getInstance()->deleteQuery($sql);
|
||||
return $result;
|
||||
}
|
||||
@@ -476,7 +481,7 @@ abstract class DbCore
|
||||
$errno = $this->getNumberError();
|
||||
if ($webservice_call && $errno)
|
||||
WebserviceRequest::getInstance()->setError(500, '[SQL Error] '.$this->getMsgError().'. Query was : '.$sql, 97);
|
||||
elseif (_PS_DEBUG_SQL_ AND $errno AND !defined('PS_INSTALLATION_IN_PROGRESS'))
|
||||
else if (_PS_DEBUG_SQL_ && $errno && !defined('PS_INSTALLATION_IN_PROGRESS'))
|
||||
{
|
||||
if ($sql)
|
||||
die(Tools::displayError($this->getMsgError().'<br /><br /><pre>'.$sql.'</pre>'));
|
||||
@@ -488,17 +493,17 @@ abstract class DbCore
|
||||
* Sanitize data which will be injected into SQL query
|
||||
*
|
||||
* @param string $string SQL data which will be injected into SQL query
|
||||
* @param boolean $htmlOK Does data contain HTML code ? (optional)
|
||||
* @param boolean $html_ok Does data contain HTML code ? (optional)
|
||||
* @return string Sanitized data
|
||||
*/
|
||||
public function escape($string, $htmlOK)
|
||||
public function escape($string, $html_ok)
|
||||
{
|
||||
if (_PS_MAGIC_QUOTES_GPC_)
|
||||
$string = stripslashes($string);
|
||||
if (!is_numeric($string))
|
||||
{
|
||||
$string = $this->_escape($string);
|
||||
if (!$htmlOK)
|
||||
if (!$html_ok)
|
||||
$string = strip_tags(Tools::nl2br($string));
|
||||
}
|
||||
|
||||
@@ -515,9 +520,9 @@ abstract class DbCore
|
||||
* @param bool $newDbLink
|
||||
* @return int
|
||||
*/
|
||||
static public function checkConnection($server, $user, $pwd, $db, $newDbLink = true)
|
||||
public static function checkConnection($server, $user, $pwd, $db, $new_db_link = true)
|
||||
{
|
||||
return call_user_func_array(array(Db::getClass(), 'tryToConnect'), array($server, $user, $pwd, $db, $newDbLink));
|
||||
return call_user_func_array(array(Db::getClass(), 'tryToConnect'), array($server, $user, $pwd, $db, $new_db_link));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,7 +533,7 @@ abstract class DbCore
|
||||
* @param string $pwd Password for database connection
|
||||
* @return int
|
||||
*/
|
||||
static public function checkEncoding($server, $user, $pwd)
|
||||
public static function checkEncoding($server, $user, $pwd)
|
||||
{
|
||||
return call_user_func_array(array(Db::getClass(), 'tryUTF8'), array($server, $user, $pwd));
|
||||
}
|
||||
@@ -539,19 +544,19 @@ abstract class DbCore
|
||||
* @acces string query The query to execute
|
||||
* @return array Array of line returned by MySQL
|
||||
*/
|
||||
static public function s($sql, $use_cache = 1)
|
||||
public static function s($sql, $use_cache = 1)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS($sql, true, $use_cache);
|
||||
return Db::getInstance()->executeS($sql, true, $use_cache);
|
||||
}
|
||||
|
||||
static public function ps($sql, $use_cache = 1)
|
||||
public static function ps($sql, $use_cache = 1)
|
||||
{
|
||||
$ret = Db::s($sql, $use_cache);
|
||||
p($ret);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
static public function ds($sql, $use_cache = 1)
|
||||
public static function ds($sql, $use_cache = 1)
|
||||
{
|
||||
Db::s($sql, $use_cache);
|
||||
die();
|
||||
|
||||
+12
-12
@@ -35,17 +35,17 @@ class DbMySQLiCore extends Db
|
||||
*/
|
||||
public function connect()
|
||||
{
|
||||
$this->_link = new mysqli($this->_server, $this->_user, $this->_password, $this->_database);
|
||||
$this->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())
|
||||
die(Tools::displayError('Link to database cannot be established : '.mysqli_connect_error()));
|
||||
|
||||
// UTF-8 support
|
||||
if (!$this->_link->query('SET NAMES \'utf8\''))
|
||||
if (!$this->link->query('SET NAMES \'utf8\''))
|
||||
die(Tools::displayError('PrestaShop Fatal error: no utf-8 support. Please check your server configuration.'));
|
||||
|
||||
return $this->_link;
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ class DbMySQLiCore extends Db
|
||||
*/
|
||||
public function disconnect()
|
||||
{
|
||||
$this->_link->close();
|
||||
$this->link->close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +61,7 @@ class DbMySQLiCore extends Db
|
||||
*/
|
||||
protected function _query($sql)
|
||||
{
|
||||
return $this->_link->query($sql);
|
||||
return $this->link->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ class DbMySQLiCore extends Db
|
||||
public function nextRow($result = false)
|
||||
{
|
||||
if (!$result)
|
||||
$result = $this->_result;
|
||||
$result = $this->result;
|
||||
return $result->fetch_assoc();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class DbMySQLiCore extends Db
|
||||
*/
|
||||
public function Insert_ID()
|
||||
{
|
||||
return $this->_link->insert_id;
|
||||
return $this->link->insert_id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +95,7 @@ class DbMySQLiCore extends Db
|
||||
*/
|
||||
public function Affected_Rows()
|
||||
{
|
||||
return $this->_link->affected_rows;
|
||||
return $this->link->affected_rows;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,7 +103,7 @@ class DbMySQLiCore extends Db
|
||||
*/
|
||||
public function getMsgError($query = false)
|
||||
{
|
||||
return $this->_link->error;
|
||||
return $this->link->error;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +111,7 @@ class DbMySQLiCore extends Db
|
||||
*/
|
||||
public function getNumberError()
|
||||
{
|
||||
return $this->_link->errno;
|
||||
return $this->link->errno;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +127,7 @@ class DbMySQLiCore extends Db
|
||||
*/
|
||||
public function _escape($str)
|
||||
{
|
||||
return $this->_link->real_escape_string($str);
|
||||
return $this->link->real_escape_string($str);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +135,7 @@ class DbMySQLiCore extends Db
|
||||
*/
|
||||
public function set_db($db_name)
|
||||
{
|
||||
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)
|
||||
|
||||
+11
-11
@@ -39,7 +39,7 @@ class DbPDOCore extends Db
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->_link = new PDO('mysql:dbname='.$this->_database.';host='.$this->_server, $this->_user, $this->_password);
|
||||
$this->link = new PDO('mysql:dbname='.$this->database.';host='.$this->server, $this->user, $this->password);
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
@@ -47,10 +47,10 @@ class DbPDOCore extends Db
|
||||
}
|
||||
|
||||
// UTF-8 support
|
||||
if ($this->_link->exec('SET NAMES \'utf8\'') === false)
|
||||
if ($this->link->exec('SET NAMES \'utf8\'') === false)
|
||||
die(Tools::displayError('PrestaShop Fatal error: no utf-8 support. Please check your server configuration.'));
|
||||
|
||||
return $this->_link;
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ class DbPDOCore extends Db
|
||||
*/
|
||||
public function disconnect()
|
||||
{
|
||||
unset($this->_link);
|
||||
unset($this->link);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ class DbPDOCore extends Db
|
||||
*/
|
||||
protected function _query($sql)
|
||||
{
|
||||
return $this->_link->query($sql);
|
||||
return $this->link->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +75,7 @@ class DbPDOCore extends Db
|
||||
public function nextRow($result = false)
|
||||
{
|
||||
if (!$result)
|
||||
$result = $this->_result;
|
||||
$result = $this->result;
|
||||
return $result->fetch();
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class DbPDOCore extends Db
|
||||
*/
|
||||
public function Insert_ID()
|
||||
{
|
||||
return $this->_link->lastInsertId();
|
||||
return $this->link->lastInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +100,7 @@ class DbPDOCore extends Db
|
||||
*/
|
||||
public function Affected_Rows()
|
||||
{
|
||||
return $this->_result->rowCount();
|
||||
return $this->result->rowCount();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +108,7 @@ class DbPDOCore extends Db
|
||||
*/
|
||||
public function getMsgError($query = false)
|
||||
{
|
||||
$error = $this->_link->errorInfo();
|
||||
$error = $this->link->errorInfo();
|
||||
return $error[2];
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class DbPDOCore extends Db
|
||||
*/
|
||||
public function getNumberError()
|
||||
{
|
||||
$error = $this->_link->errorInfo();
|
||||
$error = $this->link->errorInfo();
|
||||
return $error[1];
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ class DbPDOCore extends Db
|
||||
*/
|
||||
public function set_db($db_name)
|
||||
{
|
||||
return $this->_link->exec('USE '.pSQL($db_name));
|
||||
return $this->link->exec('USE '.pSQL($db_name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+22
-22
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -34,18 +34,18 @@ class MySQLCore extends Db
|
||||
{
|
||||
if (!defined('_PS_MYSQL_REAL_ESCAPE_STRING_'))
|
||||
define('_PS_MYSQL_REAL_ESCAPE_STRING_', function_exists('mysql_real_escape_string'));
|
||||
|
||||
if (!$this->_link = mysql_connect($this->_server, $this->_user, $this->_password))
|
||||
|
||||
if (!$this->link = mysql_connect($this->server, $this->user, $this->password))
|
||||
die(Tools::displayError('Link to database cannot be established.'));
|
||||
|
||||
if (!$this->set_db($this->_database))
|
||||
if (!$this->set_db($this->database))
|
||||
die(Tools::displayError('The database selection cannot be made.'));
|
||||
|
||||
// UTF-8 support
|
||||
if (!mysql_query('SET NAMES \'utf8\'', $this->_link))
|
||||
if (!mysql_query('SET NAMES \'utf8\'', $this->link))
|
||||
die(Tools::displayError('PrestaShop Fatal error: no utf-8 support. Please check your server configuration.'));
|
||||
|
||||
return $this->_link;
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,15 +53,15 @@ class MySQLCore extends Db
|
||||
*/
|
||||
public function disconnect()
|
||||
{
|
||||
mysql_close($this->_link);
|
||||
mysql_close($this->link);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see DbCore::_query()
|
||||
*/
|
||||
protected function _query($sql)
|
||||
{
|
||||
return mysql_query($sql, $this->_link);
|
||||
return mysql_query($sql, $this->link);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,9 +69,9 @@ class MySQLCore extends Db
|
||||
*/
|
||||
public function nextRow($result = false)
|
||||
{
|
||||
return mysql_fetch_assoc($result ? $result : $this->_result);
|
||||
return mysql_fetch_assoc($result ? $result : $this->result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see DbCore::_numRows()
|
||||
*/
|
||||
@@ -79,13 +79,13 @@ class MySQLCore extends Db
|
||||
{
|
||||
return mysql_num_rows($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see DbCore::Insert_ID()
|
||||
*/
|
||||
public function Insert_ID()
|
||||
{
|
||||
return mysql_insert_id($this->_link);
|
||||
return mysql_insert_id($this->link);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +93,7 @@ class MySQLCore extends Db
|
||||
*/
|
||||
public function Affected_Rows()
|
||||
{
|
||||
return mysql_affected_rows($this->_link);
|
||||
return mysql_affected_rows($this->link);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +101,7 @@ class MySQLCore extends Db
|
||||
*/
|
||||
public function getMsgError($query = false)
|
||||
{
|
||||
return mysql_error($this->_link);
|
||||
return mysql_error($this->link);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,31 +109,31 @@ class MySQLCore extends Db
|
||||
*/
|
||||
public function getNumberError()
|
||||
{
|
||||
return mysql_errno($this->_link);
|
||||
return mysql_errno($this->link);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see DbCore::getVersion()
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return mysql_get_server_info($this->_link);
|
||||
return mysql_get_server_info($this->link);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see DbCore::_escape()
|
||||
*/
|
||||
public function _escape($str)
|
||||
{
|
||||
return _PS_MYSQL_REAL_ESCAPE_STRING_ ? mysql_real_escape_string($str, $this->_link) : addslashes($str);
|
||||
return _PS_MYSQL_REAL_ESCAPE_STRING_ ? mysql_real_escape_string($str, $this->link) : addslashes($str);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see DbCore::set_db()
|
||||
*/
|
||||
public function set_db($db_name)
|
||||
{
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user