How to select rows where column value IS NOT NULL using CodeIgniter's ActiveRecord?

前端 未结 10 1799
太阳男子
太阳男子 2020-12-04 17:15

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         


        
相关标签:
10条回答
  • 2020-12-04 17:47

    And just to give you yet another option, you can use NOT ISNULL(archived) as your WHERE filter.

    0 讨论(0)
  • 2020-12-04 17:48

    One way to check either column is null or not is

    $this->db->where('archived => TRUE);
    $q = $this->db->get('projects');
    

    in php if column has data, it can be represent as True otherwise False To use multiple comparison in where command and to check if column data is not null do it like

    here is the complete example how I am filter columns in where clause (Codeignitor). The last one show Not NULL Compression

    $where = array('somebit' => '1', 'status' => 'Published', 'archived ' => TRUE );
    $this->db->where($where);
    
    0 讨论(0)
  • 2020-12-04 17:50
    where('archived IS NOT NULL', null, false)
    
    0 讨论(0)
  • 2020-12-04 17:50

    Null must not be set to string...

    $this->db->where('archived IS NOT', null);
    

    It works properly when null is not wrapped into quotes.

    0 讨论(0)
  • 2020-12-04 17:50

    CodeIgniter 3

    Only:

    $this->db->where('archived IS NOT NULL');
    

    The generated query is:

    WHERE archived IS NOT NULL;
    

    $this->db->where('archived IS NOT NULL',null,false); << Not necessary

    Inverse:

    $this->db->where('archived');
    

    The generated query is:

    WHERE archived IS NULL;
    
    0 讨论(0)
  • 2020-12-04 17:58

    Codeigniter generates an "IS NULL" query by just leaving the call with no parameters:

    $this->db->where('column');
    

    The generated query is:

    WHERE `column` IS NULL
    
    0 讨论(0)
提交回复
热议问题