在本课程中,他们构建了一个具有连接功能的类,如此
private function connect(){
$this->connection = new mysqli($this->host, $this->username, $this->password, $this->db_name);
if(!$this->connection){
$this->error = "Connection Failed: ".$this->connection->connect_error;
return false;
}
他们构建了像这样的函数select
public function select($query){
$result = $this->connection->query($query) or die();
}
我从未见过这样的构造与$ this-> ...-> .... 此外,函数1中的if-error不起作用,我用
替换它if(mysqli_connect_errno()) {echo("Connection failed: " . mysqli_connect_error());}
它工作正常。
什么是正确的方法。谢谢