doujia1679 2014-12-02 00:33
浏览 53

从sql查询中删除单引号

I am trying to run the sql query using codeigniter but unable to get success due to single quotes in the query. Following is my query:

function getStaffUser($uid, $participant_list=0) {

$rid='1,2,3';
$where = "FIND_IN_SET(users.role_id, '".$rid."')"; 
$where_plist = "NOT FIND_IN_SET(users.uid, '".$participant_list."')"; 

$this->db->select("users.uid, CONCAT(`users`.`given_name`, ' ',`users`.`surname`) as 'user_name'", false);
$this->db->from('users');
$this->db->where($where);
$this->db->where("users.uid!=", $uid, false);
if($participant_list!=0){

$this->db->where($where_plist, false);    
}
$data = $this->db->get();

pr($this->db->last_query()); exit;
if ($data->num_rows() == 0)
    return false;
else
    return $data->result();

}

It returns the following query:

SELECT users.uid, CONCAT(`users`.`given_name`, ' ', `users`.`surname`) as 'user_name' FROM (`users`) WHERE FIND_IN_SET(users.role_id, '1,2,3') AND users.uid!=1 AND `NOT` FIND_IN_SET(users.uid, '1,18,60')

However, the query is all fine except the single quotes only on 'NOT' in the last. If if remove that single quotes and run in the sqlyog it works fine.

Therefore, what is the best way to remove it. I tried to use false but it did not work either.

ANy help ?

Thanks.

  • 写回答

1条回答 默认 最新

  • dongquan8753 2014-12-02 00:55
    关注

    You should be able to simply use !, like this:

    $where_plist = "! FIND_IN_SET(users.uid, '".$participant_list."')"; 
    

    NOT and ! are aliases: http://dev.mysql.com/doc/refman/5.1/en/logical-operators.html#operator_not

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?