Reply
Old February 16th, 2004 Top | #1
 
siLk's Avatar
OSNN Junior Addict
Joined: January 2004
Posts: 6
Reputation: 0
Power: 81

Default connecting to two mysql databases...

...possible with php?
siLk is offline   Reply With Quote
Old February 16th, 2004 Top | #2
 
Glaanieboy's Avatar
OSNN Veteran Addict
Joined: March 2002
Location: The Netherlands
Posts: 2,647
Reputation: 270
Power: 132

Default

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.
Glaanieboy is offline   Reply With Quote
Old February 17th, 2004 Top | #3
 
Howling Wolf's Avatar
We did not deserve this !
Joined: December 2001
Location: Amongst the Native Ones
Posts: 1,259
Reputation: 330
Power: 122

Default

Should work fine as it seems so logical !

[::::::::::::::::] http://www.howling-wolf.org [::::::::::::::::]

For those who wonder, my avatar has a name: Orca (an alpha male wolf). You can visit and support 'his' site at http://www.wolfpark.org/. Thank you very much.
Howling Wolf is offline   Reply With Quote
Old February 17th, 2004 Top | #4
 
siLk's Avatar
OSNN Junior Addict
Joined: January 2004
Posts: 6
Reputation: 0
Power: 81

Default

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 is offline   Reply With Quote
Old February 17th, 2004 Top | #5
 
Glaanieboy's Avatar
OSNN Veteran Addict
Joined: March 2002
Location: The Netherlands
Posts: 2,647
Reputation: 270
Power: 132

Default

*waits* I am curious myself, I might need it too in the future.
Glaanieboy is offline   Reply With Quote
Old February 25th, 2004 Top | #6
 
siLk's Avatar
OSNN Junior Addict
Joined: January 2004
Posts: 6
Reputation: 0
Power: 81

Default

yep it works. here is the connect code I used with passwords etc removed

PHP Code:
$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 is offline   Reply With Quote
Old February 29th, 2004 Top | #7
 
siLk's Avatar
OSNN Junior Addict
Joined: January 2004
Posts: 6
Reputation: 0
Power: 81

Default

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
siLk is offline   Reply With Quote
Old March 3rd, 2004 Top | #8

OSNN Subscriber  
X-Istence's Avatar
*
Joined: December 2001
Location: USA
Posts: 6,453
Reputation: 2738
Power: 198

Default

mysql_db_select, it allows you to specify a DB connection to use.
X-Istence is offline   Reply With Quote
Old June 17th, 2005 Top | #9
 
ezfilehosting.com's Avatar
OSNN Junior Addict
Joined: June 2005
Posts: 3
Reputation: 0
Power: 0

Default 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
ezfilehosting.com is offline   Reply With Quote

Reply

Bookmarks

Thread Tools

Posting Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can 2 databases work in same tower? Heeter Windows Server Systems 2 July 26th, 2006 12:16am
opening access databases kevinfrey Windows Desktop Systems 1 November 15th, 2002 12:35am
Merging Databases in Access UofEEE Windows Desktop Systems 1 July 24th, 2002 5:07pm
connecting PC to TV ZAnwar Graphics Cards 17 July 2nd, 2002 5:25am
VPN not connecting Alliedsvcs Windows Desktop Systems 2 February 15th, 2002 6:52pm