我在我的数据库类中以这种方式实例化 $db 对象
class MysqlDB {
protected $_mysql;
protected $_where = array();
protected $_query;
protected $_paramTypeList;
protected $_crudType = null;
public function __construct($host, $username, $password, $db) {
$this->_mysql = new mysqli($host, $username, $password, $db) or die('There was a problem connecting to the database');
}
public function query($query)
{
$this->_query = filter_var($query, FILTER_SANITIZE_STRING);
$stmt = $this->_prepareQuery();
$stmt->execute();
$results = $this->_dynamicBindResults($stmt);
return $results;
}
protected function _prepareQuery()
{
echo $this->_query;
if (!$stmt = $this->_mysql->prepare($this->_query)) {
trigger_error("Problem preparing query", E_USER_ERROR);
}
return $stmt;
}
}
我在另一个类(配置文件类)中使用这个 $db 对象作为链接标识符
$db = new MysqlDb('localhost','root','','xxx');
$query=mysqli_query($db,"SELECT id, parent_id, name FROM categories_general");
我怎样才能摆脱这个错误?实际上,我最近从 MySQL 转到了 mysqli。