我正在尝试使用PHP和Mysqli中的OOP设置基本数据库类,这是我的代码
class AppDB {
private $host = "localhost";
private $user = "root";
private $password = "";
private $db = "test";
protected $_mysql;
public function __construct(){
$this->_mysql = new mysqli($host, $user, $password, $db);
if ($this->_mysql->connect_error){
die($this->_mysql->connect_error);
}
}
}
但我收到以下错误
你能告诉我为什么会这样吗?
由于
答案 0 :(得分:1)
用以下代码替换代码
public function __construct(){
$this->_mysql = new mysqli($this->host, $this->user, $this->password, $this->db);
if ($this->_mysql->connect_error){
die($this->_mysql->connect_error);
}
}