致命错误:对非对象上的成员函数FETCH_Assoc()的调用我正在尝试执行一些查询,以获得有关某些图像的一页信息。我写了一个函数function get_recent_highs($view_deleted_images=false){
$lower = $this->database->conn->real_escape_string($this->page_size * ($this->page_number - 1));
$query = "SELECT image_id, date_uploaded FROM `images` ORDER BY ((SELECT SUM( image_id=`images`.image_id ) FROM `image_votes` AS score) / (SELECT DATEDIFF( NOW( ) , date_uploaded ) AS diff)) DESC LIMIT " . $this->page_size . " OFFSET $lower"; //move to database class
$result = $this->database->query($query);
$page = array();
while($row = $result->fetch_assoc())
{
try
{
array_push($page, new Image($row['image_id'], $view_deleted_images));
}
catch(ImageNotFoundException $e)
{
throw $e;
}
}
return $page;}根据它们的受欢迎程度来选择这些图像的页面。我写了一个Database类处理与数据库和Image类,该类保存有关图像的信息。当我试图运行它时,我会得到一个错误。Fatal error: Call to a member function fetch_assoc() on a non-object$result是一个mysqli结果集,所以我很困惑为什么这个结果不起作用。
3 回答
神不在的星期二
TA贡献1963条经验 获得超6个赞
MySQli->query()
$result = $this->database->query($query);if (!$result) { throw new Exception("Database Error [{$this->database->errno}] {$this->database->error}");}
HUH函数
TA贡献1836条经验 获得超4个赞
var_dump($result)
慕容森
TA贡献1853条经验 获得超18个赞
Ex: $sql= "SELECT * FROM";$sql .= "table1";
添加回答
举报
0/150
提交
取消