我想弄清楚如何用我的类扩展 mysqli。
这是我的数据库类;
class db {
protected $_server = "localhost";
protected $_user = "root";
protected $_pwd = "";
protected $_db = "test";
protected $_charset = "utf8";
function __construct(){
$this->createConnection();
}
private function createConnection(){
$this->mysqli = new mysqli($this->_server, $this->_user, $this->_pwd, $this->_db);
$this->mysqli->query("SET NAMES ".$this->_charset);
$this->mysqli->query("SET CHARACTER SET ".$this->_charset);
if($this->mysqli->connect_error) {
//die('Error ('.$this->mysqli->connect_errno.') '.$this->mysqli->connect_error());
die();
}
//$this->mysqli->close();
}
public function mysqli_fetch_object($query){
$query = $this->mysqli->query($query);
return $query->fetch_object();
}
}
我想在这个登录类中扩展这个数据库类:
require_once("dbClass.php");
class login extends db {
public function __construct(){
}
public function check_login($email, $password) {
$email = $this->mysqli->real_escape_string($email);
$validateMail = filter_var($email, FILTER_VALIDATE_EMAIL);
$password = $password;
$database_check = $this->mysqli_fetch_object("SELECT * FROM accounts WHERE email = '$validateMail'");
}
}
我得到了这些:
Notice: Undefined property: login::$mysqli
Fatal error: Call to a member function real_escape_string() on a non-object