咨询电话:
15628812133
14
2018/07

thinkphp5视图查询方法详解

发布时间:2018-07-14 11:00:29
发布者:liyongxing
浏览量:
0

在之前的tp版本里都是在mode里进行表的关联,但是到了tp5开始就没有这个功能了

今天我就给大家介绍一下在tp5中怎样使用视图查询

视图查询是可以实现不依赖数据库视图的多表查询方法,并不需要数据库支持视图,例如:

20180714110507.jpg

这样生成的sql语句如下方

SELECT User.id,User.name,Profile.truename,Profile.phone,Profile.email,Score.score FROM think_user User INNER JOIN think_profile Profile ON Profile.user_id=User.id INNER JOIN think_socre Score ON Score.user_id=Profile.id WHERE Score.score > 80

也可以进行别名的设置

20180714110507.jpg

生成下方语句

SELECT User.id AS uid,User.name AS account,Profile.truename,Profile.phone,Profile.email,Score.score FROM think_user User INNER JOIN think_profile Profile ON Profile.user_id=User.id INNER JOIN think_socre Score ON Score.user_id=Profile.id WHERE Score.score > 80

基本的用法大体这些,希望能帮助到大家


关键词:
返回列表