Mysql Laravel 4:DB::在状态中选择
运行laravel DB::在Station中选择时,如文档所示:Mysql Laravel 4:DB::在状态中选择,mysql,laravel,laravel-4,Mysql,Laravel,Laravel 4,运行laravel DB::在Station中选择时,如文档所示: //$list_of_ids = '1,3,5,66,3' //$uid = 1 DB::select(' SELECT SUM(score) FROM user WHERE id IN (?) and user_id = ? LIMIT 4 ', array($list_of_ids,$uid)); 没有收到任何结果 但在运行时: DB::select(' SELEC
//$list_of_ids = '1,3,5,66,3'
//$uid = 1
DB::select('
SELECT SUM(score)
FROM user
WHERE id
IN (?)
and user_id = ?
LIMIT 4
', array($list_of_ids,$uid));
没有收到任何结果
但在运行时:
DB::select('
SELECT SUM(score)
FROM user
WHERE id
IN ('.$list_of_ids.') //add var here
and user_id = ?
LIMIT 4
', array($uid));
返回正确的结果,第一种方法是什么?您需要的是使用实际数组和正确的查询
$userIds = explode(',', $list_of_ids);
DB::table('user')->whereIn('id', $userIds)->where('user_id', $uid)->limit(4)->get([DB::raw('SUM(score)')]);
这里有一个解释为什么这不起作用。简短的版本是,它与Laravel无关,而是PDO本身。