Connecting to multiple MySQL servers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Connecting to multiple MySQL servers

Post by tristanlee85 »

Is it possible? I'm creating a script for http://www.tsnhosting.net that will connect to the MySQL server on http://www.turbosaturns.net and read the usernames and passwords from the phpbb database, but at the same time I need to pull information from a local database. Is something like this possible?

Code: Select all

<?php

//Attempts to connect to the local MySQL server
mysql_connect('localhost', 'username', 'password') or die(mysql_error()); 
mysql_select_db('database') or die(mysql_error());
 
//Attempts to connect to the remote MySQL server
mysql_connect('remotehost', 'username', 'password') or die(mysql_error()); 
mysql_select_db('database') or die(mysql_error());

?>
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

Simple, you assign a var to each mysql_connect ($var=mysql_connect()) and then when you do a query or othe MySQL operation, add in a , and put the connection var after it
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Absolutely possible, but time consuming for the user and a resource hog for all servers involved. Strongly suggest moving all data to a central, quickly accessible (i.e. the same hosting site / network as the PHP server) MySQL server.
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Thank you both. I'd move the information to the same server, but I'm designing this for someone else so I'm trying to work with his options.
Post Reply