Romantic Electron Romantic Electron - 3 months ago 6
MySQL Question

how to bind several columns to one variable in PDO like query?

I have a variable

and I want to search for records containing the
in multiple columns

$query="Select * from products where name LIKE ? OR color LIKE ?"
$stmt = $this->pdo->prepare($query);

but when I try to execute
, I get nothing displayed except for a '1'.The problem perhaps is binding of the
variable to the query.So I am curious whether there's a way to handle such a situation and what's the best working alternative.Thanks


$results is the success status of the PDOStatement execution; the returned rows are still in the $stmnt object. You need to iterate over the returned rows and print the individually.

while ($row = $stmnt->fetch(PDO::FETCH_ASSOC)) {

will work.