我更改了我的域和主机,并将所有代码从第一台主机移至另一台带有数据库的主机。现在,我在 open-cart 1.5.6 中遇到错误
PHP Fatal error: Call to undefined method mysqli::escape() in /home/l/beta4/system/library/db.php on line 24
我的主机是 Godaddy。
这是我的 db.php 代码
<?php
class DB {
private $driver;
public function __construct($driver, $hostname, $username, $password, $database) {
$file = DIR_DATABASE . $driver . '.php';
if (file_exists($file)) {
require_once($file);
$class = 'DB' . $driver;
$this->driver = new $driver($hostname, $username, $password, $database);
} else {
exit('Error: Could not load database driver type ' . $driver . '!');
}
}
public function query($sql) {
return $this->driver->query($sql);
}
public function escape($value) {
return $this->driver->escape($value);
}
public function countAffected() {
return $this->driver->countAffected();
}
public function getLastId() {
return $this->driver->getLastId();
}
}
?>
第24行的代码是
public function escape($value) { return $this->driver->escape($value); }
最佳答案
您要么更新了 Opencart,要么更改了数据库驱动程序,要么两者都更改了。您应该确保在问题中包含此类详细信息。
DB 类在 1.5.6 中有一个错误 - 更改如下行:
$this->driver = new $driver($hostname, $username, $password, $database);
到
$this->driver = new $class($hostname, $username, $password, $database);
此外,您应该将 mysqli 驱动程序 system/database/mysqli.php 替换为 1.5.6.4 的版本,可以下载 here或之后:
$this->link->set_charset("utf8");
添加
$this->link->query("SET SQL_MODE = ''");
关于php - 打开购物车 - PHP fatal error :在/home/l/beta4/system/library/db.php 中调用未定义的方法 mysqli::escape() 第 24 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42366928/