connecting to two mysql databases...

Glaanieboy

OSNN Veteran Addict
Joined
Mar 6, 2002
Messages
2,626
#2
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.
 

siLk

OSNN Newbie
Joined
Jan 13, 2004
Messages
6
#4
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...
 

siLk

OSNN Newbie
Joined
Jan 13, 2004
Messages
6
#6
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
 

siLk

OSNN Newbie
Joined
Jan 13, 2004
Messages
6
#7
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
 

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,979
Messages
673,325
Members
89,020
Latest member
Amanda99