如何联接来自不同数据库的两个表 [英] How to join two tables from different databases

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

问题描述

如何联接来自不同数据库的两个表.一个数据库是本地主机,另一个数据库在线.

How to join two tables from different databases. One database is localhost, the other is in online.

$connectA = mysql_connect('localhost','root','','abc');
$connectB = mysql_connect('xxx','yyy','zzz','xyz');

我要从具有数据库 abc xyz 的表部门中加入部门名称.

I want to join department_name from table department which is having database abc and xyz.

推荐答案

使用SQL JOINS的时间不能超过join的时间.是因为SQL查询总是发送到特定的数据库或服务器.

You cannot as long as by join you mean using SQL JOINS. It is, because SQL query is always sent to specific database or server.

您需要发送两个独立的查询,每个数据库一个,然后在PHP中提供一些逻辑以通过array_merge(完全连接)或更高级的脚本将它们联接.

You need to send two independent queries, one for each database and then provide some logic in PHP to join them either by array_merge (full join) or some more advanced scripting.

如果看不到自己的代码就无济于事.

Can't help more without seeing some code of your own.

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

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