Fatal error: Call to a member function fetch_assoc() on boolean in - error

When I run this:

while ($array = $queryGallery->fetch_assoc()) {
    $gallery[] = $array;
}

I end up with the following error:

Fatal error: Call to a member function fetch_assoc() on boolean in .

How do I resolve it?