Page 1 of 1

Connecting to multiple MySQL servers

Posted: Sun Jun 18, 2006 6:03 pm
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());

?>

Posted: Sun Jun 18, 2006 6:15 pm
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

Posted: Sun Jun 18, 2006 6:35 pm
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.

Posted: Sun Jun 18, 2006 9:05 pm
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.