我正在尝试创建一个脚本,我可以继续引用它来显示数据库条目。我相信我的问题是当我尝试显示结果时,我不知道如何调用 mysqli 和查询。我得到的错误是调用非对象上的成员函数 fetch_row()
class connectDatabase {
public $category;
public $query;
public $mysqli;
public function __construct($DB_HOST, $DB_USER, $DB_PWD, $DB_NAME)
{
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PWD, $DB_NAME);
return $this->mysqli = $mysqli;
}
public function queryInformation($category) {
$query = "SELECT * FROM postad WHERE `category` = $this->category ORDER by date desc";
return $this->query = $query;
}
public function displayResult() {
$mysqli = $this->mysqli ;
$query = $this->query;
$result = $mysqli->query($query);
while ($row = $result->fetch_row()) {
echo "$row[1] $row[2] $row[3] $row[4] </br>" ;
}
}
}