Prepared statement placeholders can only represent SINGLE values.
e.g.
$foo = '1,2,3';
$db->prepare("SELECT ... WHERE foo in (:foo)");
bind(':foo', $foo);
would create a query that's interpreted as
SELECT ... WHERE foo IN ('1,2,3');
Note the quotes - your three separate numbers are now a single-valued string, and the query runs as if it had been written:
SELECT ... WHERE foo='1,2,3'
You'd have to build a dynamic statement and create as many placeholders as you have values.
foreach ($values as $val) {
$placeholders[] = '?';
}
$sql = "SELECT ... WHERE foo IN (" . implode(',', $placeholders) . ")";
...prepare/bind other values
$stmt->execute($values);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…