2015-10-12 42 views
5

我試圖創建下面的語句NULL:值不是笨

select * from donors where field is NOT NULL; 

使用CodeIgniter,我的代碼看起來是這樣的:

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

[Codeigniter Where子句]的可能重複(http://stackoverflow.com/questions/10109047/codeigniter-where-clause) – vhu

回答

29

,當你看到documentation您可以使用$this->db->where()與第三個參數設置爲FALSE以避免查詢。 例子:

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

或者你可以使用自定義的查詢字符串這樣

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

所以,你的查詢生成器看起來就像這樣:

$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'); 
1

試試這個:

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