搜索
系统检测到您的用户名不符合规范:

6.0.13framework 2.0.54think-orm的union问题

浏览:780 发布日期:2022年08月08日
5.0.0 - 严重 - 未处理
// 6.0.13framework 2.0.54think-orm
$query = Db::table('table')->where('id', 3738)->buildSql();
$data = Db::table('table')->order('id','desc')->limit(10)->union($query)->buildSql();
echo $data;
// 运行结果:
( SELECT * FROM `table` UNION ( ( SELECT * FROM `table` WHERE `id` = 3738 ) ) ORDER BY `id` DESC LIMIT 10 )
// 想要的结果:
( SELECT * FROM `table` ORDER BY `id` DESC LIMIT 10) UNION ( SELECT * FROM `table` WHERE `id` = 3738 )

// laravel类似代码对比,laravel版本8.75

// limit和orderByDesc在union前面:
$sql = DB::table('table')->where('id', '=', '3728');
$data = DB::table('table')->limit(10)->orderByDesc('id')->union($sql)->toSql();
// 运行结果
(select * from `table` order by `id` desc limit 10) union (select * from `table` where `id` = ?)

// limit和orderByDesc在union后面:
$sql = DB::table('table')->where('id', '=', '3728');
$data = DB::table('table')->union($sql)->limit(10)->orderByDesc('id')->toSql();
// 运行结果
(select * from `table`) union (select * from `table` where `id` = ?) order by `id` desc limit 10
评论()
后面还有条评论,
评论支持使用[code][/code]标签添加代码
您需要登录后才可以评论 登录 | 立即注册
提交Bug
JunStar
积分:806 等级:LV2

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /