我的主机已将 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);
}
}
?>
最佳答案
如果我们希望该消息消失并能够登录我们的管理页面,我们应该如何进行?
- 打开文件
<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 - Opencart 1.4.9 从 mysql 到 mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32695568/