php - Opencart 1.4.9 从 mysql 到 mysqli

标签 php mysql mysqli opencart

我的主机已将 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/

相关文章:

javascript - 返回 false 被 onsubmit 忽略

java - 如何在 PHP 中复制 Java 加密?

php - 复选框细化使用逗号分隔字段存储的 mysql 表的搜索

php - 对mysql数据进行计数和分组

php cURL - 请求必须分块或具有内容长度

php - Xpath路径帮助

php - 如何从自定义 MySQL 获取函数中检索 1 个结果

php - 为什么我在对象上调用函数时会在非对象上出现此函数调用错误?

php - 子查询计算错误?

php - 一行返回 SQL 查询,用 PHP 获取