MySQL Forums
Forum List  »  PHP

Query from multiple databases
Posted by: Davor Ergotic
Date: April 19, 2012 03:24PM


I have a problem.
Need to select (at least) 2 databases from 2 different locations and cross-reference tables.

So I'm doing this:
$db_1_connection = mysql_connect('$host_1', '$user_1', '$pass_1');
$db_1_db_select = mysql_select_db($db_1_connection);

$db_2_connection = mysql_connect('$host_2', '$user_2', '$pass_2');
$db_2_db_select = mysql_select_db($db_2_connection);

And then I'm trying to select some columns from some tables on those 2 databases but can't get it to work.

$select = "SELECT db1.table_1.column_1, db2.table_1.column_1 FROM db1.table_1, db2.table_1 WHERE .. ";

It won't work because of
$result = mysql_query($select, $db_2_connection);

connection (2nd parameter) of mysql_query function.

Please can somebody help me?
How to execute query on 2 tables in 2 different databases on 2 different connections?


Options: ReplyQuote

Written By
Query from multiple databases
April 19, 2012 03:24PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.