数据库返回Bool而不是SQL

I'm having a problem when I try to run a search program I made. When I do:

if (isset($query)) {
    $query = preg_replace("#[^0-9a-z]#i", "", $query);
    $query = array($db->q("select * from posts where title like $query") , 
    $db->q("select count(*) from posts where title like $query"));  

    if ($query[1] == 0){
        $out = "Sorry: There is no results";
    } else {
        while ($row = mysql_fetch_array($query[0])){
             $title = $row['title'];
             $exep = $row['exepert'];
             $out .= "<div>".$title."".$exep."</div>";
        }
    }
}

It always says there are no search results, but when I force it to go to the else statement it says both the results and the count are booleans (the number 0).

If anybody needs extra code to help me please ask!

Thanks in advance!

Assuming that your magical $db object there is some kind of wrapper for MySQLi, both MySQLi::query() and MySQLi::prepare() will return false on failure (see the dock) by default.

You should either alter your code to deal with it directly or right after establishing of connection do this:

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

It will cause all SQL errors to throw exception. IMHO, that makes for easier development process. And you can also integrate those exceptions in your persistence logic, since they will also get thrown in case of integrity violations (like, when user attempts to make a duplicate in a column marked as UNIQUE).