简体   繁体   中英

Joining tables from 2 different connection strings

I need to join two tables from different MySQL (PHP) connection strings and different databases.

$conn = mysql_connect('192.168.30.20', 'user', 'pass');
$conn2 = mysql_connect('anotherIPHere', 'user2', 'pass2');

$db = mysql_select_db('1stdb', $conn);
$db2 = mysql_select_db('2nddb', $conn2);

If I were using the same connection I would just prefix the tables with the db names, such as database1.table1.column and database2.table2.column2, but since I'm using two completely separate connection strings the MySQL Query does not know which connection string to use, thus the resource is not usable.

I've read a ton of resources that show how to use two databases, from the SAME connection string and that is working fine, but I can't find anything related to multiple connection strings and databases.

Thanks

There's no way to do it in the query. About the only possibility is if you use a MySQL FEDERATED Table which lets you access tables on remote servers.

You can't do it database-server-side, that's for sure. You'll have to download the filtered rowset for each table you want to join against, then iterate manually in-code to join the two sets of rows where you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM