与codeIgniter查询MySQL中,选择行,其中字段为空 [英] Querying MySQL with CodeIgniter, selecting rows where field is NULL

查看:102
本文介绍了与codeIgniter查询MySQL中,选择行,其中字段为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这仅返回此查询:

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

存档字段是 DATE 字段。

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

解决方案

 其中(存档IS NOT NULL',空,假)
 

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)

这篇关于与codeIgniter查询MySQL中,选择行,其中字段为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆