$prepare = $db -> prepare("SELECT * FROM table WHERE a = ?"); $prepare -> execute(["value"]); 

Please tell me how to get the result of the SELECT in this case, because EXECUTE produces the type BOOL . Through QUERY, everything works directly, but how to do it through PREPARE ?

  • See the fetch methods. fetchAll, fetchColumn they are called after execute to get the data itself - Mike

1 answer 1

To do this, you can use one of the fetch functions, for example, fetchAll()

 $prepare = $db -> prepare("SELECT * FROM table WHERE a = ?"); $prepare -> execute(["value"]); $results = $prepare->fetchAll(); foreach($results as $result) echo $result['name']."<br />"; 
  • so simple? Thank you, the answer is lying on the surface! I tried $ r = $ prepare -> execute (["value"]) -> fetchAll (); - did not go, and it was confusing - tonchikp