代码点火器 - 使用where和like的MySQL查询

Al *_*sen 3 php mysql codeigniter

我已经搜索过每一个答案,但没有描述我想要的东西,或者我没有理解它们.所以这就是我的问题.我想要一个像这样的"复杂"查询:

select * from MyTable
where PropertyA='$propertyValue'
and (id like '%$someValue%' or name like '%$someValue%' or description like '%$someValue%') 
order by id desc limit 10 offset $offsetValue
Run Code Online (Sandbox Code Playgroud)

如何在代码点火器中编写此查询?$propertyValue, $someValue, $offsetValue都是php变量.当然我需要避免sql注入.我也在phpmyadmin测试了这个,我的查询工作正常.

Sat*_*aty 9

对于SQL注入,使用绑定查询和活动记录是安全的,它将使您免于SQL注入,因为框架完成了逃避易受攻击的用户输入的所有工作.

您只需在Active record FOR 3.X版本中编写代码即可

$this->db->select('*');
$this->db->where('PropertyA', $propertyValue);
$this->db->group_start();
$this->db->like('id', $someValue);
$this->db->or_like('name', $someValue);
$this->db->or_like('description', $someValue);
$this->db->group_end();
$this->db->order('id','desc')
$this->db->limit($limit, $start);// add your limit here
$this->db->get('MyTable');
Run Code Online (Sandbox Code Playgroud)