$this->db->where_in('k.profile1_id', $value);
$this->db->or_where_in('k.profile2_id', $value);
$this->db->or_where_in('k.profile3_id', $value);
我如何修改上面的代码以在Mysql中的WHERE后面获得一个额外的括号?
WHERE ( `k`.`profile1_id` IN ('1') OR `k`.`profile2_id` IN ('1') OR `k`.`profile3_id` IN ('1`') )
我尝试过:-
$this->db->group_start();
$this->db->where_in('k.profile1_id', $value);
$this->db->or_where_in('k.profile2_id', $value);
$this->db->or_where_in('k.profile3_id', $value);
$this->db->group_end();
但它似乎不起作用
使用自定义字符串:-
$a = $this->db->where("(`k.profile1_id` = '$value' OR `k.profile2_id` = '$value' OR `k.profile3_id` = '$value')")->where("(`k.profile4_id` = '$value')")->get('table_name')->result_array();
这会生成如下的sql:-
SELECT * FROM `table_name` WHERE (`k.profile1_id` = 'value' OR `k.profile2_id` = 'value' OR `k.profile3_id` = 'value') AND (`k.profile4_id` = 'value')
$value = $this->db->escape($value);
$condition = "(k.profile1_id IN ($value) or k.profile2_id IN ($value) or k.profile3_id IN ($value))";
$this->db->where($condition);
$result = $this->db->get("table_name")->result();
请参阅此以避免注释中建议的CI中的sql注入,并了解有关CI中查询生成器的更多信息。