我正在尝试创建以下语句:
select * from donors where field is NOT NULL;
使用codeigniter,我的代码如下所示:
$where = ['field' => NULL];
$this->db->get_where('table', $where);
答案 0 :(得分:48)
当您看到documentation时,您可以将$this->db->where('field is NOT NULL', NULL, FALSE);
与第三个参数设置为FALSE,以免转义您的查询。
例如:
$where = "field is NOT NULL";
$this->db->where($where);
或者你可以像这样使用自定义查询字符串
$this->db->select('*');
$this->db->where('field is NOT NULL', NULL, FALSE);
$this->db->get('donors');
因此,您的查询构建器将如下所示:
$this->db->select('*');
$where = "field is NOT NULL";
$this->db->where($where);
$this->db->get('donors');
OR
{{1}}
答案 1 :(得分:7)
试试这个:
$this -> db -> get_where('donors', array('field !=' => NULL));
答案 2 :(得分:0)
如果你有一些复杂的查询,其中有多个where和Having条件。
请在下面找到示例:
$this->db->select(['id', 'email_address', 'abandon_at','datediff(now(),`abandon_at`) AS daysdiff ' ]);
$this->db->having('daysdiff < 11');
$query = $this->db->get_where('forms', array('abandon_form' => 1,'abandon_at !=' => 'NULL') );
return $query->result();
答案 3 :(得分:0)
尝试一下:
$this->db->where('columnName !=', null);