对于如何使用准备好的查询设置SQL IN语句,我有点困惑。代码如下:
$in = implode(\',\', array_fill(0, count($product_ids), \'%d\'));
$results = $this->db->get_results($this->db->prepare("SELECT ID, post_title FROM {$this->db->posts} WHERE ID NOT IN({$in}) AND post_type=%s ORDER BY ID DESC LIMIT %d", array(implode(\',\', $product_ids), "post", $num)));
结果返回null。我错在哪里?
更新:修复了我自己的问题。以下是我的解决方案:
$prepare = array();
$in = implode(\',\', array_fill(0, count($product_ids), \'%d\'));
foreach ($product_ids as $ids){
$prepare[] = $ids;
}
$prepare[] = "post";
$prepare[] = $num;
$results = $this->db->get_results($this->db->prepare("SELECT ID, post_title FROM {$this->db->posts} WHERE ID NOT IN({$in}) AND post_type=%s ORDER BY ID DESC LIMIT %d", $prepare));