It is not possible how you try it. You should have a separate placeholder for each parameter that you want to pass, everything else will ignore the purpose of the parameters (which separate the code from the data).
$ids = array(2, 4, 6, 8); // prepare a string that contains ":id_0,..,:id_n" and include it in the SQL $plist = ':id_'.implode(',:id_', array_keys($ids)); $sql = "SELECT * FROM someTable WHERE someId IN ($plist)"; // prepare & execute the actual statement $parms = array_combine(explode(",", $plist), $ids); $stmt = $PDO->prepare($sql); $rows = $stmt->execute($parms);
If you manage to pass an array of values ββto one parameter during the binding, you will be allowed to modify the SQL statement. That would be a loophole for SQL injection - nothing could guarantee that all array values ββwould be generally innocent.
source share