nitation Posted December 14, 2007 Share Posted December 14, 2007 Hello Phpfreakers, I just wanna ask how to connect to multiple databases residing on different host/server. I have to retrieve information from a separate host/server mysql's database. Thank you in advance. Quote Link to comment Share on other sites More sharing options...
ManOnScooter Posted December 14, 2007 Share Posted December 14, 2007 I would suggest an if statement for every condition.. a simple function for selection of the database doing this segregation.. lemme know if i got this question right.. I see this as a straight forward code Quote Link to comment Share on other sites More sharing options...
marcus Posted December 14, 2007 Share Posted December 14, 2007 No. Use separate connections. <?php $connection1 = mysql_connect("host","user","pass") or die (mysql_error()); $database1 = mysql_select_db("database", $connection1); $connection2 = mysql_connect("host","user","pass") or die (mysql_error()); $database2 = mysql_select_db("database", $connection2); $sql = "SELECT * FROM `table`"; $res = mysql_query($sql, $database1) or die(mysql_error()); $sql2 = "SELECT * FROM `table2`"; $res2 = mysql_query($sql2, $database2) or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
nitation Posted December 14, 2007 Author Share Posted December 14, 2007 So in this regard, will the "host" still remain localhost or the dns of the host am retrieving the information from. Let say ; mysql_connect("localhost/dns(ip)", "user", "password") or die (mysql_error()); Quote Link to comment Share on other sites More sharing options...
revraz Posted December 14, 2007 Share Posted December 14, 2007 localhost means just that, a server that is running on the same server as the webserver. It's either localhost or a DNS/IP, but not both. Quote Link to comment Share on other sites More sharing options...
nitation Posted December 17, 2007 Author Share Posted December 17, 2007 ravrez i don't meant that. I was only asking what will be the host to connect to the other database. Is it gonna remain as localhost or what? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.