PHP PDO MySQL IN (?,?,?...

Posted by nute on Stack Overflow See other posts from Stack Overflow or by nute
Published on 2010-05-11T21:08:58Z Indexed on 2010/05/11 21:14 UTC
Read the original article Hit count: 539

Filed under:
|
|
|

I want to write a MySQL statement like:

SELECT * FROM someTable WHERE someId IN (value1, value2, value3, ...)

The trick here is that I do not know ahead of time how many values there will be in the IN().

Obviously I know I can generate the query on the go with string manipulations, however since this will run in a loop, I was wondering if I could do it with a PDO PreparedStatement.

Something like:

$query = $PDO->prepare('SELECT * FROM someTable WHERE someId IN (:idList)');
$query->bindValue(':idList', implode(',', $idArray));

Is that possible?

© Stack Overflow or respective owner

Related posts about php

Related posts about pdo