tp5.1 查询字段为空的数据

[NOT] IN查询支持使用闭包方式

[NOT] NULL :

查询字段是否(不)是Null,例如:

Db::name('user')->where('name', null)
->where('email','null')
->where('name','not null')
->select();

实际生成的SQL语句为:

SELECT * FROM `think_user` WHERE  `name` IS NULL  AND `email` IS NULL  AND `name` IS NOT NULL

如果你需要查询一个字段的值为字符串null或者not null,应该使用:

Db::name('user')->where('title','=', 'null')
->where('name','=', 'not null')
->select();

推荐的方式是使用whereNullwhereNotNull方法查询。

Db::name('user')->whereNull('name')
->whereNull('email')
->whereNotNull('name')
->select();

官方教程:https://www.kancloud.cn/manual/thinkphp5_1/354004

猜你喜欢

转载自blog.csdn.net/haibo0668/article/details/82288855