Laravel:加入两个不同数据库连接的表 [英] Laravel : join two tables of different db connections

查看:141
本文介绍了Laravel:加入两个不同数据库连接的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以联接两个不同数据库连接的表(两个不同服务器中的mysql和oracle)根据条件?

Is it possible to join two tables of different db connections (mysql and oracle in two different servers) based on condition?

我要执行此查询:

DB::connection('oracle')->table('SYSADM.PS_KS_COM_PERS_INF AS PRES')
->join(DB::connection('mysql')->table('students AS STU'), 
'PRES.NATIONAL_ID','=','STU.NationalID')
->where('PRES.STUDENT_STATUS', '=', 'Record Closed')
->where('STU.Batch', '=', $value->Batch)
->get(); // or count();

我为每个表和连接创建了模型,

I created model of each table and connection,

但是我无法加入两个数据库连接的两个模型

but I couldn't join two models of two db connections

推荐答案

是否可以联接两个不同数据库连接的表(两个不同服务器中的mysql和oracle)

Is it possible to join two tables of different db connections (mysql and oracle in two different servers)

否.

Oracle确实通过其

Oracle does offer heterogeneous access via its Database Gateway for ODBC feature. Once that feature is rigged up correctly, you'll be able to run queries like this.

 DB::connection('oracle')->table('some_oracle_table')->join('some_mysql_table@mysqlConnection') ...

说明如何装配该功能超出了堆栈溢出答案的范围.获取您的DBA帮助.

Explaining how to rig that feature is waaaaaay beyond the scope of a Stack Overflow answer. Get your DBA to help.

或者,只需分别从Oracle连接和MySQL连接读取数据,并将它们与程序关联.这就是今年完成工作的方式.

Or, just read the data from your Oracle connection and your MySQL connection separately and correlate them in your program. That's the way to get the job done this year.

这篇关于Laravel:加入两个不同数据库连接的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆