Page 1 of 1

how to connect multiple database servers

Posted: Mon Oct 09, 2006 2:49 am
by itsmani1
Hi all....

my question is if we have more than one database server and with different type of access rights like on server one we can write and on server 2 and 3 we can't write, we have just reading access.

how to make the connection string for this type of Scenario?

Remember we all the databases are for one application.

any help?

thanks in advance.

Posted: Mon Oct 09, 2006 2:58 am
by s.dot
You can create multiple database connections.

Code: Select all

$database1 = mysql_connect('severname', $username, $password);
mysql_select_db('database_name', $database1);

$database2 = mysql_connect('servername2', $username2, $password2);
mysql_select_db('database_name2', $database2);
You can then query each specific database server by using the resource links you just created.

Code: Select all

//this will query the $database1 connection
$sample_query = mysql_query("SELECT * FROM `users`", $database1);

//this will query the $database2 connection
$sample_query2 = mysql_query("INSERT INTO  `users` VALUES('bob')", $database2);

Posted: Mon Oct 09, 2006 3:04 am
by itsmani1
thanks man

I will try this and hope this will work easily.