mysqli_fetch_object不返回对象

时间:2014-10-13 14:17:36

标签: php object mysqli

这是我的问题:

$row = mysqli_fetch_object(mysqli_query("SELECT * FROM `page` AS p LEFT JOIN `page_settings` AS s ON p.id = s.page_id WHERE p.id = '".$this->id."'"));
echo $row->title;

此查询返回如下错误:

Notice: Trying to get property of non-object in...

但是当我尝试这个查询时:

$row = mysqli_fetch_object(mysqli_query("SELECT * FROM `page` WHERE id = '".$this->id."'"));
echo $row->title;

完美无缺。我什么都不懂。

1 个答案:

答案 0 :(得分:1)

您收到Trying to get property of non-object错误的原因是因为您的查询未通过,因此它不是对象,而是错误消息(在某​​些情况下为null)。

答案是,因为您的查询失败了。