基于Can I bind an array to an IN() condition?
上述问题对使用多个WHERE
子句没有任何答案。
第二个最佳答案仅适用于一个WHERE
子句:
$qMarks = str_repeat('?,', count($ids) - 1) . '?';
$sth = $db->prepare("SELECT * FROM myTable WHERE id IN ($qMarks)");
$sth->execute($ids);
如果我添加了额外的WHERE
子句,则会产生空结果或错误。
$qMarks = str_repeat('?,', count($ids) - 1) . '?';
$sth = $db->prepare("SELECT * FROM myTable WHERE id IN ($qMarks) AND locationid=?");
$sth->execute(array($ids, ?)); // Also tried $sth->execute($ids, $location_id) and $sth->execute($ids, array($location_id));
请告知。