如何使用CodeIgniter的ActiveRecord选择列值不为空的行? [英] How to select rows where column value IS NOT NULL using CodeIgniter's ActiveRecord?
本文介绍了如何使用CodeIgniter的ActiveRecord选择列值不为空的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用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
字段.
有没有更好的方法来解决这个问题?我知道我可以自己编写查询,但是我想在代码中坚持使用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选择列值不为空的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文