本文主要是介绍laravel跨库jion查询,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先laravel跨库需要设置2个库,通过在env和database.php中设置
查询
$dbExam = env('DB_EXAM_DATABASE', 'xxx');$dbLegal = env('DB_DATABASE', 'xxx');$data = DB::table($dbExam.'.x2_examhistory as emh')->select(DB::raw('lli.name, lli.idcard, lli.phone, lls.name,lli.created_at,llu.nick_name,emh.ehusername, emh.ehexam, emh.ehscore score, emh.ehtime, FROM_UNIXTIME(emh.ehstarttime,"%Y-%m-%d %H:%i:%s") as ehstarttime'))->leftJoin($dbExam.'.x2_user as emu', 'emu.userid', '=', 'emh.ehuserid')->leftJoin($dbLegal.'.users as llu', 'llu.openid', '=', 'emu.useropenid')->leftJoin(DB::raw('(SELECT * FROM '.$dbLegal.'.exam_user_infos GROUP BY id ) lli'), 'lli.user_id', '=', 'llu.id')->leftJoin(DB::raw('(SELECT * FROM '.$dbLegal.'.state_organs GROUP BY id) lls'), 'lli.state_organ_communty', '=', 'lls.id')->where('llu.id', $userId)->groupBy('emh.ehuserid')->orderBy('emh.ehid')->limit(10000)->get();
这篇关于laravel跨库jion查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!