douvcpx6526 2016-06-14 10:06
浏览 69

通过两个连接加入laravel

I have two connection in laravel, and I want to connect both

I tried like this

$response = DB::connection('connection1')->table('table1 as t1');
$response->DB::connection('connection2')->leftJoin('table2 as t2', 't2.t1_id','=','t2.id')
->get();

But query fails, how to join this, please help.

Just like I can do in mysql like this,

SELECT *
FROM [MyDatabaseOnDB1].[dbo].[MyTable] tab1
INNER JOIN [DB2].[MyDatabaseOnDB2].[dbo].[MyOtherTable] tab2
    ON tab1.ID = tab2.ID

How can do this in laravel.

Please comment, If you give me negative votes please..

  • 写回答

2条回答 默认 最新

  • doumen1883 2016-06-14 10:23
    关注

    To join two different database tables you have to use query builder in laravel 5.2

    I think this will help you and working fine in my case.

      $sql="select * from database1.table1 left join database2.table2 on database2.table2.table2Id=database1.table1.table1Id" 
          $data = DB::select($sql);
    

    Hope it will help you...

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题