0

The following query is supposed to return three rows, but it returns only one:

$sql = $dbh->prepare("SELECT * FROM table_name WHERE state = ? AND id IN(?) AND status IN(?)");
$sql->execute(array(1, '1,2,3', '1,2,3'));

However, the same query executed without bound parameters as the argument to the IN() function returns 3 rows, as it's supposed to:

$sql = $dbh->prepare("SELECT * FROM table_name WHERE state = ? AND id IN(1,2,3) AND status IN(1,2,3)");
$sql->execute(array(1));

Why does this happen, and how do I correctly bind 1,2,3 as the argument to IN()?

Cedric Ipkiss
  • 5,662
  • 2
  • 43
  • 72
  • An explanation: [Prepared statements and IN clause](https://phpdelusions.net/pdo#in) – Your Common Sense Oct 16 '17 at 06:34
  • This explanation actually provided a response (given there are other placehoders in my query), contrary to the question this is marked as a duplicate of which deals with a single placeholder. The solution here is thus to use `array_merge` to join all variables into a single array. Thanks, @YourCommonSense – Cedric Ipkiss Oct 16 '17 at 06:44

0 Answers0