本文介绍了如何清除准备语句中的单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的查询如下:
$group_id = $session['group_id'];
$sql = "SELECT *
FROM notification
WHERE group_id IN(?)";
$result = $this->db->query($sql, array($group_id))->result_array();
当我添加: echo $ this-> db-> last_query (); die();
,结果如下:
When I add : echo $this->db->last_query();die();
, the result is like this :
SELECT * FROM notification WHERE group_id IN('1,13,2')
我想删除单引号,是这样的:
I want remove single quotes in order to the result is like this :
SELECT * FROM notification WHERE group_id IN(1,13,2)
如何删除prepare语句中的单引号?
How to remove single quotes in prepare statement?
推荐答案
您可以如下:
$ session ['group_id'] 可能是一个字符串。因此您可以将该字符串转换为数组。
$session['group_id'] is probably a string. so you can convert that string into an array.
$group_id = explode(",", $session['group_id']);
现在$ group_id已经是一个数组。因此,在下面的语句中,用'$ group_id'替换 array($ group_id):
Now $group_id is already an array. So, in below statement replace array($group_id) with just '$group_id':
$result = $this->db->query($sql, array($group_id))->result_array();
所以整个代码如下:
$group_id = explode(",", $session['group_id']);
$sql = "SELECT *
FROM notification
WHERE group_id IN(?)";
$result = $this->db->query($sql, array($group_id))->result_array();
这篇关于如何清除准备语句中的单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!