connecting to two mysql databases...

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
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
13 Jan 2004
Messages
6
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...
 

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
*waits* I am curious myself, I might need it too in the future.
 

siLk

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

X-Istence

*
Political Access
Joined
5 Dec 2001
Messages
6,498
mysql_db_select, it allows you to specify a DB connection to use.
 

Members online

No members online now.

Latest profile posts

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.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?

Forum statistics

Threads
62,007
Messages
673,466
Members
5,598
Latest member
Larry Chris