I have trouble returning data in rows in MySQL prepared statement using string binding with commas as WHERE
IN
condition.
My string is as follows:
$order_ids = '200,201,202';
And here's my query statement:
$stmt = $conn->prepare("
SELECT id FROM TABLE
WHERE t.order_id IN (:order_ids)
");
$stmt->bindParam(':order_ids', $order_ids);
$stmt->execute();
while($row = $stmt->fetch()) {
echo $row['id'];
}
I'm supposed to get id 200, 201, 202 from the rows returns but it returns only the first row.
It works if I hardcoded the exact ids into the query statement without params binding, like so:
$stmt = $conn->prepare("
SELECT id FROM TABLE
WHERE t.order_id IN (200,201,202)
");