Is there a (complex / non-standard) way to do this?
There will be something like
$stmt = $db->prepare( 'SELECT title FROM episode WHERE id IN (?, ?, ?, ?);
work? Therefore, if I wanted to find a variable number of identifiers, can I do
$ids = array(1,2,3,4,5,6,7); $idSection = implode(array_pad(array(), count($ids), '?'))
Even if this works, it is still not very useful to use multiple datasets with the same prepared statement, unless the search in $ids is repeated every time and it does not work with name placeholders.
I guess what you do
$stmt = $db->prepare( 'SELECT title FROM episode WHERE id IN (:ids); $ids = implode('","' array(1,2,3,4,5,6,7)); $stmt->bindParam( ':ids', $ids);
It fails because the prepared statement was designed so that it looked for the same id value and "1", "2", "3", "4", "5", "6", "7" 't match ?
I am sure there is a better answer than just not using IN(...) clauses. Should I just clear the term $ids manually and include it in the request without placeholders?
$stmt = $db->prepare( "SELECT title FROM episode WHERE id IN $ids AND genre like :genre"); $stmt->bindParam( ':genre', '%$genre%);