connecting to two mysql databases...

Yep.
Code:
$connection_one = mysql_connect("server1","user","pass");
$connection_two = mysql_connect("server2","user,"pass");

mysql_select_db("db1",$connection_one);
mysql_select_db("db2",$connection_two);

mysql_query("SELECT * FROM bla1",$connection_one);
mysql_query("SELECT * FROM bla2",$connection_two);

mysql_close($connection_one);
mysql_close($connection_two);
This should work. Theoratically that is, because I have never tried it.
 
ok I'll give it a shot, I am pretty sure I have tried this in the past, but I might have done something wrong then ;)

I'll edit this post if it works or not...
 
*waits* I am curious myself, I might need it too in the future.
 
yep it works. here is the connect code I used with passwords etc removed ;)

PHP:
$conn = mysql_connect("localhost", "username", "password");
mysql_select_db("database_1_name", $conn);
mysql_select_db("database_2_name", $conn);

you can see this in effect at http://www.wcreplays.com/db_test.php the top 2 rows of usernames were pulled from a seperate database that I use for the staff backend, and the huge list below it is the list of forum usernames
 
sorry took so long to reply.

anyway, you can do it by connecting to the database you want to execute the query on before the query is executed. That's the only way ive been able to get it to work correctly

$db_one_connection
$query_one

$db_two_connection
$query_two

etc
 
mysql_db_select, it allows you to specify a DB connection to use.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back