I'm using PHP, MySQL and PDO.
$ids = '1,2,3';
I have a query like this which works:
SELECT *
FROM table
WHERE id IN($ids)
This returns 3 rows as expected
If I use:
SELECT *
FROM table
WHERE id IN(:ids)
$stmt = $this->db->prepare($q);
$params = array('ids' => $ids);
$stmt->execute($params);
It only returns 1 row.
How can I bind the ids?
According to https://phpdelusions.net/pdo I should use:
$arr = [1,2,3];
$in = str_repeat('?,', count($arr) - 1) . '?';
$sql = "SELECT * FROM table WHERE column IN ($in)";
but how can I put my ids of 1,2,3 which are stored in $ids into $arr = [1,2,3] because if I write
$arr = [$ids]
it's basically writing
$arr = ['1,2,3']
instead of
$arr = [1,2,3]