Value IS NOT NULL in codeigniter

noushid p picture noushid p · Oct 12, 2015 · Viewed 68.9k times · Source

I am trying to create the following statement:

select * from donors where field is NOT NULL;

With codeigniter, my code looks like this:

$where = ['field' => NULL];
$this->db->get_where('table', $where);

Answer

Ari Djemana picture Ari Djemana · Oct 15, 2015

when you see documentation You can use $this->db->where() with third parameter set to FALSE to not escape your query. Example:

$this->db->where('field is NOT NULL', NULL, FALSE);

Or you can use custom query string like this

$where = "field is  NOT NULL";
$this->db->where($where);

So your query builder will look like this:

$this->db->select('*');
$this->db->where('field is NOT NULL', NULL, FALSE);
$this->db->get('donors');

OR

$this->db->select('*');
$where = "field is  NOT NULL";
$this->db->where($where);
$this->db->get('donors');