首页 » 网站推广 » phpsql不履行技巧_thinkphp6 查询前提为空时部分sql语句不实行问题

phpsql不履行技巧_thinkphp6 查询前提为空时部分sql语句不实行问题

访客 2024-12-18 0

扫一扫用手机浏览

文章目录 [+]

$list = self::where($where)->order($sort,$order)->page(PAGE, LIMIT)->select()->toArray();$count=self::where($where)->field("sum(money) as money, sum(tax_money) as tax_money,sum(number) as number, count(id) as count")->find();

如果$where是空数组,那么$count是查不到数据的,但是$list能有值;我用

var_dump(self::getLastSql());

打印sql,只能打印$list 的sql,$count该当就没实行;但是这样写是没问题的:

phpsql不履行技巧_thinkphp6 查询前提为空时部分sql语句不实行问题

$list = self::where($where)->order($sort,$order)->page(PAGE, LIMIT)->select()->toArray(); $count = self::where($where)->count();

$count是能查询到值的,我搜索了一下,thinkphp客服回答是这样的:6.0便是这么设计的 没有查询条件 是不会实际进行查询的。

phpsql不履行技巧_thinkphp6 查询前提为空时部分sql语句不实行问题
(图片来自网络侵删)

也便是说须要查询条件才能正常查询,那么给啥通用的查询条件?可以这么写:

$list = self::where($where)->order($sort,$order)->page(PAGE, LIMIT)->select()->toArray(); $count=self::where($where)->field("sum(money) as money, sum(tax_money) as tax_money,sum(number) as number, count(id) as count")->order("id desc")->find();

$count 加上一个order就能查询到数据了。

标签:

相关文章

php常量率低技巧_PHP 常量详解教程

PHP 常量常量是单个值的标识符(名称)。在脚本中无法改变该值。有效的常量名以字符或下划线开头(常量名称前面没有 $ 符号)。注释...

网站推广 2024-12-19 阅读0 评论0