如何联接来自不同数据库的两个表 [英] How to join two tables from different databases
问题描述
如何联接来自不同数据库的两个表.一个数据库是本地主机,另一个数据库在线.
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屋!