码迷,mamicode.com
首页 > 其他好文 > 详细

selectRaw

时间:2017-07-23 12:41:25      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:nec   nsf   使用   sel   art   mysql内置函数   pre   text   config   

mysql内置函数:date
select date("2010-08-17 19:08:28");显示是"2010-08-17"

在laravel中使用内置函数的时候必须使用selectRaw() 这个方法,但是当涉及到多表连接查询的时候就的带上前缀,下面有条没用的sql语句作为实例
$prefix = config("database.connections.mysql.prefix");
$res = DB::table(‘transfer_project as tp‘)
->leftJoin(‘user_orders as uo‘, ‘tp.user_order_id‘, ‘=‘, ‘uo.order_id‘)
->selectRaw("date(".$prefix."tp.transfer_start) as transfer_start,date(".$prefix."tp.transfer_stop) as transfer_stop");

单表的时候就不需要加上前缀了。

selectRaw

标签:nec   nsf   使用   sel   art   mysql内置函数   pre   text   config   

原文地址:http://www.cnblogs.com/lengthuo/p/7224000.html

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