Answer the question
In order to leave comments, you need to log in
How to bind an array of values in an IN condition when using PDO?
<?php
$ids=array(1,2,3,7,8,9);
$db = new PDO(...);
$stmt = $db->prepare(
'SELECT *
FROM table
WHERE id IN(:an_array)'
);
$stmt->bindParam('an_array',$ids);
$stmt->execute();
?>
Answer the question
In order to leave comments, you need to log in
Classic solution:
<?php
$ids=array(1,2,3,7,8,9);
$in = str_repeat('?,', count($arr) - 1) . '?';
$stmt = $db->prepare('SELECT * FROM table WHERE id IN($in)');
$stmt->execute($ids);
Not too pretty, but safe.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question