Mysqli WHERE给出一个布尔错误

时间:2015-05-10 12:46:24

标签: php mysqli

所以我试图只获得active = 1的行,但出于某种原因,它给了我这个错误。

Call to a member function fetch_object() on boolean

$db2 = new mysqli('localhost', 'root', '', '123');
$imagesQuery = $db2->query("
SELECT
images.id,
images.caption,
images.active,
COUNT(images_likes.id) AS likes

FROM images WHERE active = 1

LEFT JOIN images_likes 
ON images.id = images_likes.image

GROUP BY images.id
");

while($row = $imagesQuery->fetch_object()) {
    $images[] = $row;
} 
echo '<pre style="color: #fff">', print_r($images, true) , '</pre>';

1 个答案:

答案 0 :(得分:0)

SELECT
images.id,
images.caption,
images.active,
COUNT(images_likes.id) AS likes

FROM images 

LEFT JOIN images_likes 
ON images.id = images_likes.image
WHERE active = 1
GROUP BY images.id