且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP PDO:数组中更新SQL WHERE IN()子句

更新时间:2023-02-15 10:12:38

一个占位符只能重新present单个原子值。它还挺工作的原因是因为价值的mysql看到的是形式为123456,这是间$ P $点作为一个整数,但丢弃一旦遇到非数字部分(逗号)字符串的其余部分。

A placeholder can only represent a single, atomic value. The reason it kinda works is because the value mysql sees is of the form '123,456' which it interprets as an integer, but discards the rest of the string once it encounters the non numeric part(the comma).

相反,像做

$list = join(',', array_fill(0, count($ids), '?'));
echo $sql = "...where notification_id IN ($list)";
$this->dbh->prepare($sql)->execute(array_values($ids));