出现语法错误或访问冲突:1064您的SQL语法有错误;流明5.6

时间:2018-06-27 02:45:26

标签: php mysql eloquent lumen laravel-query-builder

这是我在控制器上的代码,get_time_age()是控制器上的函数

//create query contents inner joint users
    $content = DB::table('contents')
                    ->join('users', 'contents.user_id', '=', 'users.iduser')
                    ->select('contents.idcontent', 'contents.user_id', 'users.nickname', 'contents.title', 'contents.content', 
                            'contents.createdate', 'contents.modifieddate', (DB::raw($this->get_time_ago(strtotime("contents.createdate")).' as timelapse')), 
                            'contents.delete')
                    ->where('contents.delete', 0)
                    ->orderBy('idcontent', 'desc')
                    ->get();

我得到一个错误 SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法有错误

at Connection-> select('选择contentsidcontentcontentsuser_idusersnickname,{{1 }}。contentstitlecontentscontentcontentscreatedatecontents,间隔了48年,modifieddatecontents来自{{1}上的delete内部联接contentsusers = contentsuser_id其中usersiduser =?在Builder.php第1963行中按contents desc',array(0),true)排序

1 个答案:

答案 0 :(得分:3)

您必须将get_time_ago()的字符串结果用引号引起来:

DB::raw("'".$this->get_time_ago(strtotime("contents.createdate"))."' as timelapse")