Skip navigation links

MySQL Forums :: PHP :: Query from multiple databases


Advanced Search

Re: Query from multiple databases
Posted by: Davor Ergotic ()
Date: April 22, 2012 01:26PM

Tx all for reply but I found a solution.
After reading about 50 different articles on the web I found the solution.

This is the code:
$sql = "SELECT p1.column1, p1.column2, p2.column1, p3.column1, p3.column2 FROM (database1.table1 p1 LEFT OUTER JOIN $database2.table1 p2 ON p1.id = p2.id) LEFT OUTER JOIN database1.table2 p3 on p1.id = p3.id WHERE p1.column3 = 'something' ";

And the thing is that you must connect with the user which has privileges to all databases you want to use.
So I used:
mysql_connect('localhost', 'username', 'password');

I didn't select database!! Just connected to the MySQL server!

Anyway, thx to all!!!

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.