将逗号分隔的 id 列表绑定到我准备好的语句时,我只返回一行,而我期望的是 3。
<?php
$dbh = new PDO("mysql:host=127.0.0.1;dbname=database", "user", "password");
$stmt = $dbh->prepare('SELECT * FROM Person WHERE PersonID IN (:p)');
$stmt->bindValue(":p", "3,4,5");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<pre>
<?php print_r($result); ?>
</pre>
如果我将 stmt 更改为
SELECT * FROM Person WHERE PersonID IN (3,4,5)
我按预期返回了 3 行,我很困惑!