在 PHP OOP 数据库 Class __construct() 上出现错误
Getting Error on PHP OOP Database Class __construct()
我正在尝试在 PHP 和 Mysqli 中使用 OOP 来设置基本数据库 class,这是我的代码
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);
}
}
}
但我收到以下错误
你能告诉我为什么会这样吗?
谢谢
用下面的代码替换代码
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);
}
}
我正在尝试在 PHP 和 Mysqli 中使用 OOP 来设置基本数据库 class,这是我的代码
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);
}
}
}
但我收到以下错误
你能告诉我为什么会这样吗?
谢谢
用下面的代码替换代码
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);
}
}