与codeIgniter查询MySQL中,选择行,其中字段为空字段、为空、codeIgniter、MySQL

2023-09-08 15:50:03 作者:照不完的美╰

我用codeIgniter的活动记录类查询MySQL数据库。我需要选择表中的行,其中一个字段设置为NULL:

  $这个 - > DB-化合物其中(存档=!','空');
$ Q = $这个 - > DB->获得(项目);
 

这仅返回此查询:

  SELECT * FROM WHERE存档='NULL'项目!;
 

存档字段是 DATE 字段。

有没有更好的办法来解决这个问题?我知道我可以只编写查询自己,但我wan't在我的code的活动记录要坚持。

解决方案

 其中(存档IS NOT NULL',空,假)
 
在Word2010中筛选非空字段收件人记录

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->db->where('archived !=', 'NULL');
$q = $this->db->get('projects');

That only returns this query:

SELECT * FROM projects WHERE archived != 'NULL';

The archived field is a DATE field.

Is there a better way to solve this? I know I can just write the query myself, but I wan't to stick with the Active Record throughout my code.

解决方案

where('archived IS NOT NULL', null, false)