Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在查询的WHERE子句中添加一个左括号?_Php_Codeigniter - Fatal编程技术网

Php 如何在查询的WHERE子句中添加一个左括号?

Php 如何在查询的WHERE子句中添加一个左括号?,php,codeigniter,Php,Codeigniter,我如何修改上面的代码,在Mysql中的WHERE后面加上一个括号 $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); 我试过:- WHERE ( `k`.`profile1_id` IN ('1') OR `k`.`pro

我如何修改上面的代码,在Mysql中的WHERE后面加上一个括号

$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);
我试过:-

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();
请参阅注释中建议的避免CI中的sql注入,并了解有关CI中查询生成器的更多信息。

使用自定义字符串:-

$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();
这将生成如下所示的sql:-

$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();

这不是CI风格。这是个可怕的想法,因为它为SQL提供了一个很好的攻击向量。injections@NicoHaase感谢您的输入,我现在已经更新了答案。您希望从
表中选择*其中
k.profile1\u id
IN('$value')或
k.profile2\u id
IN('$value')或
k.profile3\u id
IN('$value'))出于好奇:你为什么在乎?如果有什么不起作用,那么请分享更多细节。我也有一个优先权问题,我希望在如下位置旁边加一个括号:“选择*FROM
table_name
where(
k.profile1_id
IN('$value')或
k.profile2_id
IN('$value')或
k.profile3_id
IN('$value')))及(@您好,请立即尝试更新答案,并让我知道发生了什么???。
SELECT * FROM `table_name` WHERE (`k.profile1_id` = 'value' OR `k.profile2_id` = 'value' OR `k.profile3_id` = 'value') AND (`k.profile4_id` = 'value')