Joining tables from 2 different connection strings

Posted by krio on Stack Overflow See other posts from Stack Overflow or by krio
Published on 2010-03-31T21:20:59Z Indexed on 2010/03/31 21:23 UTC
Read the original article Hit count: 271

Filed under:
|

Hello,

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

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql