【发布时间】:2017-11-18 16:26:43
【问题描述】:
基于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));
请指教。
【问题讨论】:
标签: php arrays pdo prepared-statement where-in