NOT NULL value in codeigniter

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); 
+16
source share
4 answers

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

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

Or you can use a 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'); 
+50
source

Try the following:

 $this -> db -> get_where('donors', array('field !=' => NULL)); 
+7
source

If you have a complex query with several parameters where and Have.

The following is an example:

 $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(); 
0
source

Try it:

 $this->db->where('columnName !=', null); 
0
source

All Articles