I\'m using CodeIgniter\'s Active Record class to query the MySQL database. I need to select the rows in a table where a field is not set to NULL:
$this->d
Much better to use following:
For is not null:
where('archived IS NOT NULL', null);
For is null:
where('archived', null);
$this->db->or_where('end_date IS', 'NULL', false);
You can do (if you want to test NULL)
$this->db->where_exec('archived IS NULL)
If you want to test NOT NULL
$this->db->where_exec('archived IS NOT NULL)
The Active Record definitely has some quirks. When you pass an array to the $this->db->where()
function it will generate an IS NULL. For example:
$this->db->where(array('archived' => NULL));
produces
WHERE `archived` IS NULL
The quirk is that there is no equivalent for the negative IS NOT NULL
. There is, however, a way to do it that produces the correct result and still escapes the statement:
$this->db->where('archived IS NOT NULL');
produces
WHERE `archived` IS NOT NULL