By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

using 2 or 3 Databases in PHP!!!

P: 11
i'm having this project where i need to be connected to more than 1 database > i've used php before so any redirection to articles or tutorial would be helpful.

thnx for your time
Feb 13 '08 #1
Share this Question
Share on Google+
5 Replies


P: 59
Hi,

You can just use the query in this way,

mysql_query = "SELECT * FROM database1.table1,database2.table2,database3.table3 WHERE id='1'";

With regards
Feb 13 '08 #2

P: 11
thnx for your reply

what about the config file? i still need a new statment to connect to 2 DB
Feb 13 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
thnx for your reply

what about the config file? i still need a new statment to connect to 2 DB
See the following entry in the mysql_select_db chapter of the PHP manual
at multiple dbs
Just incase the mysql_select_db() function still won't work with multiple database connections (as has happened to me before).

$dbh1 = mysql_pconnect($host,$user,$pass);
$dbh2 = mysql_pconnect($host,$user,$pass);

You could do this...

mysql_query("USE database1",$dbh1);
mysql_query("Use database2",$dbh2);

This does the same thing as the mysql_select_db() function...

or this...

You don't even have to select the database for each connection.

mysql_query("SELECT * FROM database1.table",$dbh1);
mysql_query("SELECT * FROM database2.table",$dbh2);
Ronald
Feb 13 '08 #4

P: 11
appreciate your fast help ronverdonk
thnx alot
Feb 13 '08 #5

ronverdonk
Expert 2.5K+
P: 4,258
appreciate your fast help ronverdonk
thnx alot
You are welcome. See ya again.

Ronald
Feb 13 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.