我正在使用 Codeigniter 2。我正在尝试使用 Active Record 进行 mysql 查询。问题是当传递给 where_in 的数组为空时出现错误。我问如果数组为空,是否有任何方法可以忽略 where_in
条件
这是条件示例:
$this->db->where_in('p.brand_id', $brands);
这是我得到的错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND
p
.brand_id
IN ()
最佳答案
如果数组为空,则不要调用 where_in()
。
if(is_array($brands) && count($brands) > 0){
$this->db->where_in('p.brand_id', $brands);
}
关于mysql - 如果数组为空,where_in codeigniter 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22356372/