如何使用 CodeIgniter 的 ActiveRecord 选择列值不是 NULL 的行? [英] How to select rows where column value IS NOT NULL using CodeIgniter's ActiveRecord?

查看:26
本文介绍了如何使用 CodeIgniter 的 ActiveRecord 选择列值不是 NULL 的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CodeIgniter 的 Active Record 类来查询 MySQL 数据库.我需要选择字段未设置为 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');

那只返回这个查询:

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

archived 字段是一个 DATE 字段.

The archived field is a DATE field.

有没有更好的方法来解决这个问题?我知道我可以自己编写查询,但我想在我的代码中坚持使用 Active Record.

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

推荐答案

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

这篇关于如何使用 CodeIgniter 的 ActiveRecord 选择列值不是 NULL 的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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