I need to build an SQL statement in PHP using PDO and the number of values in the WHERE clause are dynamic.
e.g.
SELECT column1, column2 FROM table WHERE category = :category OR category = :category
In this case there are 2 categories in the where clause I'm comparing, but it could be more than 2 so I can't just use :category1 and :category2 as the names.
I tried the following, but it's giving a "General error: 2031" message
$where = array("category = :category", "category = :category");
$params = array("abc", "xyz");
$query = "SELECT column1, column2 FROM table WHERE ". implode(" OR ", $where);
$s= $h->prepare($query);
$s->setFetchMode(PDO::FETCH_ASSOC);
$s->execute(array_values($params));
Any suggestions?