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.
 

ezfilehosting.com

OSNN Newbie
Joined
17 Jun 2005
Messages
3
Re: connecting to 2 mysql databases...

I have a question can these 2 database be join together? www.ezfilehosting.com/forum

and www.ezfilehosting.com/a I would like to know if I cna connect and how can I connect them? I try wat you guys posted above and I cannot get it to work :(
 

Members online

No members online now.

Latest profile posts

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?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!
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!

Forum statistics

Threads
61,997
Messages
673,411
Members
5,590
Latest member
AntonioPR