Reputation: 6330
I am trying to set up a basic database class using OOP in PHP and Mysqli and here is the code I have
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);
}
}
}
but I am getting following errors
Can you please let me know why this is happening?
Thanks
Upvotes: 0
Views: 126
Reputation: 585
Replace the code with below code
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);
}
}
Upvotes: 1