码迷,mamicode.com
首页 > Web开发 > 详细

thinkphp5 链式操作alias别名用法

时间:2020-10-05 21:57:56      阅读:39      评论:0      收藏:0      [点我收藏+]

标签:thinkphp   www   thinkphp5   其他   tab   链式   table   用法   sql   

alias用于设置当前数据表的别名,便于使用其他的连贯操作例如join方法等。

示例:

Db::table(‘think_user‘)->alias(‘a‘)->join(‘DEPT b ‘,‘b.user_id= a.id‘)->select();
最终生成的SQL语句类似于:

SELECT * FROM think_user a INNER JOIN think_dept b ON b.user_id= a.id
v5.0.2+版本开始,可以传入数组批量设置数据表以及别名,例如:

Db::table(‘think_user‘)->alias([‘think_user‘=>‘user‘,‘think_dept‘=>‘www.96net.com.cn‘])->join(‘think_dept‘,‘dept.user_id= user.id‘)->select();

最终生成的SQL语句类似于:

SELECT * FROM think_user user INNER JOIN think_dept dept ON dept.user_id= user.id

thinkphp5 链式操作alias别名用法

标签:thinkphp   www   thinkphp5   其他   tab   链式   table   用法   sql   

原文地址:https://blog.51cto.com/13959155/2540024

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!