codeigniter 中的值不为空
Value IS NOT NULL in codeigniter
我正在尝试创建以下语句:
select * from donors where field is NOT NULL;
使用 codeigniter,我的代码如下所示:
$where = ['field' => NULL];
$this->db->get_where('table', $where);
当您看到 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');
或
$this->db->select('*');
$where = "field is NOT NULL";
$this->db->where($where);
$this->db->get('donors');
试试这个:
$this -> db -> get_where('donors', array('field !=' => NULL));
如果您有一些包含多个 where 和 Having 条件的复杂查询。
请看下面的例子:
$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();
试试这个:
$this->db->where('columnName !=', null);
我正在尝试创建以下语句:
select * from donors where field is NOT NULL;
使用 codeigniter,我的代码如下所示:
$where = ['field' => NULL];
$this->db->get_where('table', $where);
当您看到 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');
或
$this->db->select('*');
$where = "field is NOT NULL";
$this->db->where($where);
$this->db->get('donors');
试试这个:
$this -> db -> get_where('donors', array('field !=' => NULL));
如果您有一些包含多个 where 和 Having 条件的复杂查询。
请看下面的例子:
$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();
试试这个:
$this->db->where('columnName !=', null);