在PHP OOP数据库类上获取错误__construct()

时间:2015-03-10 06:39:42

标签: php oop mysqli

我正在尝试使用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);
          }
   }

}

但我收到以下错误

enter image description here

你能告诉我为什么会这样吗?

由于

1 个答案:

答案 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);
          }
   }