简体   繁体   中英

Mysqli WHERE gives an boolean error

So I am trying to get only rows where active = 1 but for some reason it's giving me out this error.

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>';
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM