How to select rows where column value IS NOT NULL using CodeIgniter's ActiveRecord?
where('archived IS NOT NULL', null, false)
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
Null must not be set to string...
$this->db->where('archived IS NOT', null);
It works properly when null is not wrapped into quotes.