When We have WHERE condition in SELECT query, we can use PDO’s prepare statement:
$sth = $db->prepare("SELECT name FROM mytable WHERE id > :id");
$sth->execute( array(":id"=>2) );
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
So we obtain variable $result which type is array.
But when we dont have WHERE condition, we dont need prepare statement right? we use only query
$result = $db->query("SELECT name FROM books");
but now, $result type is not array, but pdostatement.
What is best way, for obtain also array types (and not pdostatement) in situations like this?
In other words,
$db->query()does bothprepare()andexecute()