我正在使用 code igniter 方式来编写查询。但是,它不起作用,当我调试它时,显示我的查询中添加了 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
最佳答案
您使用的 SQL 函数具有此语法,FIND_IN_SET(needle, haystack)
。第二个参数是一个字符串,您提供的字符串是“关键字”。显然字符串“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');
关于php - 代码点火器在 WHERE 子句后附加 IS NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39411669/