Skip navigation links

MySQL Forums :: PHP :: Query from multiple databases


Advanced Search

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

Hi,

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?

Thx!
Davor

Options: ReplyQuote


Subject Written By Posted
Query from multiple databases Davor Ergotic 04/19/2012 03:24PM
Re: Query from multiple databases Peter Brawley 04/19/2012 04:50PM
Re: Query from multiple databases Rick James 04/21/2012 01:36PM
Re: Query from multiple databases Peter Brawley 04/21/2012 09:09PM
Re: Query from multiple databases Davor Ergotic 04/22/2012 01:26PM
Re: Query from multiple databases Peter Brawley 04/23/2012 09:58PM
Re: Query from multiple databases Davor Ergotic 04/26/2012 03:00PM
Re: Query from multiple databases obaid ahmed 04/28/2012 12:43AM


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.