MySQL codeigniter 中的值不是 NULL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33076281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:19:23  来源:igfitidea点击:

Value IS NOT NULL in codeigniter

mysqlcodeigniter-3

提问by noushid p

I am trying to create the following statement:

我正在尝试创建以下语句:

select * from donors where field is NOT NULL;

With codeigniter, my code looks like this:

使用 codeigniter,我的代码如下所示:

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

回答by Ari Djemana

when you see documentationYou can use $this->db->where()with third parameter set to FALSE to not escape your query. Example:

当您看到文档时,您可以使用$this->db->where()将第三个参数设置为 FALSE 来不转义您的查询。例子:

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

Or you can use 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');

回答by Deniz B.

Try this:

尝试这个:

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

回答by Nileshsinh Rathod

If you have some a complex query with multiple where and Having condition.

如果您有一些具有多个 where 和 Have 条件的复杂查询。

Please find below 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();

回答by Janu Dewangga

Try this:

尝试这个:

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