Opencart 1.4.9 从 mysql 到 mysqli
Opencart 1.4.9 from mysql to mysqli
我的主机已将其 PHP 升级到 5.5 版并将 MySQL 升级到 5.6 版。
我们仍在使用 Opencart 1.4.9.6,不能立即升级,因为商店已经上线,我们有很多自己的修改。
现在我们无法查看我们的管理区域,此消息显示在我们所有页面的顶部:
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/public_html/system/database/mysql.php on line 8
如果我们希望消息消失并能够登录到我们的管理页面,我们应该如何进行?是否可以将 mysql_connect
更改为 mysqli
?
这是 mysql.php
中使用的代码:
<?php
final class MySQL {
private $connection;
public function __construct($hostname, $username, $password, $database) {
if (!$this->connection = mysql_connect($hostname, $username, $password)) {
exit('Error: Could not make a database connection using ' . $username . '@' . $hostname);
}
if (!mysql_select_db($database, $this->connection)) {
exit('Error: Could not connect to database ' . $database);
}
mysql_query("SET NAMES 'utf8'", $this->connection);
mysql_query("SET CHARACTER SET utf8", $this->connection);
// mic changed 20100824 instead of SET NAMES and CHARACTER SET
// see: http://at2.php.net/manual/en/function.mysql-set-charset.php
//mysql_set_charset( 'utf8', $this->connection );
mysql_query("SET CHARACTER_SET_CONNECTION=utf8", $this->connection);
mysql_query("SET SQL_MODE = ''", $this->connection);
}
public function query($sql) {
$resource = mysql_query($sql, $this->connection);
if ($resource) {
if (is_resource($resource)) {
$i = 0;
$data = array();
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
mysql_free_result($resource);
$query = new stdClass();
$query->row = isset($data[0]) ? $data[0] : array();
$query->rows = $data;
$query->num_rows = $i;
unset($data);
return $query;
} else {
return TRUE;
}
} else {
exit('Error: ' . mysql_error($this->connection) . '<br />Error No: ' . mysql_errno($this->connection) . '<br />' . $sql);
}
}
public function escape($value) {
return mysql_real_escape_string($value, $this->connection);
}
public function countAffected() {
return mysql_affected_rows($this->connection);
}
public function getLastId() {
return mysql_insert_id($this->connection);
}
public function __destruct() {
mysql_close($this->connection);
}
}
?>
Is it possible to just change mysql_connect to mysqli?
不,这还不够。您必须更改从 mysql_ 启动的所有函数。不过,这并不难。你只需要给一个小时时间的程序员。
How should we proceed if we want the message to disappear
只需禁用它。
error_reporting(E_ALL & ~E_DEPRECATED);
and be able to log in to our admin pages?
这是所有问题中最难的一个。你最好问问前面提到的程序员,因为可能有其他错误阻止你登录。
如果我们希望消息消失并能够登录到我们的管理页面,我们应该如何进行?
- 打开文件
<OC_ROOT>/system/startup.php
- 更改此行:
error_reporting(E_ALL)
至
error_reporting(E_ALL ^ E_DEPRECATED)
,现在所有弃用警告都将消失
是否可以只将 mysql_connect 更改为 mysqli?
我不知道 OC 1.4.9 是否有内置的 mysqli 驱动程序,要检查,打开目录 <OC_ROOT>/system/database
并确保有一个名为 mysqli.php
的文件,如果存在,则应用以下步骤:(如果没有,您需要更改项目中的所有 mysql_*
函数)
- 打开配置文件
<OC_ROOT>/config.php
和 <OC_ROOT>/admin/config.php
- 更改此行:
define('DB_DRIVER', 'mysql')
至
define('DB_DRIVER', 'mysqli')
我的主机已将其 PHP 升级到 5.5 版并将 MySQL 升级到 5.6 版。
我们仍在使用 Opencart 1.4.9.6,不能立即升级,因为商店已经上线,我们有很多自己的修改。
现在我们无法查看我们的管理区域,此消息显示在我们所有页面的顶部:
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/public_html/system/database/mysql.php on line 8
如果我们希望消息消失并能够登录到我们的管理页面,我们应该如何进行?是否可以将 mysql_connect
更改为 mysqli
?
这是 mysql.php
中使用的代码:
<?php
final class MySQL {
private $connection;
public function __construct($hostname, $username, $password, $database) {
if (!$this->connection = mysql_connect($hostname, $username, $password)) {
exit('Error: Could not make a database connection using ' . $username . '@' . $hostname);
}
if (!mysql_select_db($database, $this->connection)) {
exit('Error: Could not connect to database ' . $database);
}
mysql_query("SET NAMES 'utf8'", $this->connection);
mysql_query("SET CHARACTER SET utf8", $this->connection);
// mic changed 20100824 instead of SET NAMES and CHARACTER SET
// see: http://at2.php.net/manual/en/function.mysql-set-charset.php
//mysql_set_charset( 'utf8', $this->connection );
mysql_query("SET CHARACTER_SET_CONNECTION=utf8", $this->connection);
mysql_query("SET SQL_MODE = ''", $this->connection);
}
public function query($sql) {
$resource = mysql_query($sql, $this->connection);
if ($resource) {
if (is_resource($resource)) {
$i = 0;
$data = array();
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
mysql_free_result($resource);
$query = new stdClass();
$query->row = isset($data[0]) ? $data[0] : array();
$query->rows = $data;
$query->num_rows = $i;
unset($data);
return $query;
} else {
return TRUE;
}
} else {
exit('Error: ' . mysql_error($this->connection) . '<br />Error No: ' . mysql_errno($this->connection) . '<br />' . $sql);
}
}
public function escape($value) {
return mysql_real_escape_string($value, $this->connection);
}
public function countAffected() {
return mysql_affected_rows($this->connection);
}
public function getLastId() {
return mysql_insert_id($this->connection);
}
public function __destruct() {
mysql_close($this->connection);
}
}
?>
Is it possible to just change mysql_connect to mysqli?
不,这还不够。您必须更改从 mysql_ 启动的所有函数。不过,这并不难。你只需要给一个小时时间的程序员。
How should we proceed if we want the message to disappear
只需禁用它。
error_reporting(E_ALL & ~E_DEPRECATED);
and be able to log in to our admin pages?
这是所有问题中最难的一个。你最好问问前面提到的程序员,因为可能有其他错误阻止你登录。
如果我们希望消息消失并能够登录到我们的管理页面,我们应该如何进行?
- 打开文件
<OC_ROOT>/system/startup.php
- 更改此行:
error_reporting(E_ALL)
至
error_reporting(E_ALL ^ E_DEPRECATED)
,现在所有弃用警告都将消失
是否可以只将 mysql_connect 更改为 mysqli?
我不知道 OC 1.4.9 是否有内置的 mysqli 驱动程序,要检查,打开目录 <OC_ROOT>/system/database
并确保有一个名为 mysqli.php
的文件,如果存在,则应用以下步骤:(如果没有,您需要更改项目中的所有 mysql_*
函数)
- 打开配置文件
<OC_ROOT>/config.php
和<OC_ROOT>/admin/config.php
- 更改此行:
define('DB_DRIVER', 'mysql')
至
define('DB_DRIVER', 'mysqli')