【TP5】对多表进行操作

浏览:1317 发布日期:2018/09/11 分类:技术分享
如果需要对多表进行操作,可以这样使用:
Db::field('user.name,role.title')
->table('think_user user,think_role role')
->limit(10)->select();

为了尽量避免和mysql的关键字冲突,可以建议使用数组方式定义,例如:
Db::field('user.name,role.title')
->table(['think_user'=>'user','think_role'=>'role'])
->limit(10)->select();
使用数组方式定义的优势是可以避免因为表名和关键字冲突而出错的情况。
最佳答案
评论( 相关
后面还有条评论,点击查看>>