0
基於Can I bind an array to an IN() condition?PDO:使用多個WHERE子句將數組綁定到IN()條件?
上面的問題沒有任何答案使用多個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));
請指教。