代码点火器在WHERE子句后追加IS NULL

时间:2016-09-09 12:30:48

标签: php mysql codeigniter

我使用代码点火器的方式来编写查询。但是,它不起作用,当我肆意妄为时,在我的查询中添加了IS NULL。

$select_fields  = "id,name,created_by,keywords";
$where_field    = "FIND_IN_SET('$id','keywords')";

$this -> db_social -> select($select_fields);
$this -> db_social -> from('user_collection1');
$this -> db_social -> where($where_field);
$query  = $this->db_social->get();

错误显示此类查询

SELECT `id`, `name`, `created_by`, `keywords` FROM `user_collection1` WHERE FIND_IN_SET('11','keywords') IS NULL

1 个答案:

答案 0 :(得分:0)

您使用的SQL函数具有此语法FIND_IN_SET(needle, haystack)。第二个参数是一个字符串,您提供的字符串是“keywords”。显然字符串“11”不在字符串“keywords”中。

我认为你完全不使用db->where()功能就能得到你所需要的东西。 试一试。

$select  = "id,name,created_by,keywords WHERE FIND_IN_SET('$id', keywords)";

$this->db_social->select($select);
//don't need the ->from call since this uses a single table, put that name in ->get
$query  = $this->db_social->get('user_collection1');
相关问题