redarrow Posted September 14, 2007 Share Posted September 14, 2007 advance thank you. Is this possable to connect to two diffrent database then echo result. if so how do you do it intresting cheers. <?php $db1=mysql_connect("http://www.database_server1","username1","password1"); mysql_connect("database1",$db1); $db2=mysql_connect("http://www.database_server2","username2","password2"); mysql_connect("database2",$db2); $query="select database1.username,database2.surname from userinfo join database1.username as a and database2.surname as b were a='$user_id' and b='$user_id'"; $result=mysql_query($query); while($list=mysql_fetch_assoc($result)){ echo " ".$list['a']." <br> ".$list['b']." "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69283-conecting-to-two-sep-databases-with-join/ Share on other sites More sharing options...
btherl Posted September 14, 2007 Share Posted September 14, 2007 You can pass the mysql link identifier as an argument to mysql_query() Quote Link to comment https://forums.phpfreaks.com/topic/69283-conecting-to-two-sep-databases-with-join/#findComment-348165 Share on other sites More sharing options...
jitesh Posted September 14, 2007 Share Posted September 14, 2007 you can use "mysql_db_query" to run queries with different database. resource mysql_db_query ( string database, string query [, resource link_identifier] ) Quote Link to comment https://forums.phpfreaks.com/topic/69283-conecting-to-two-sep-databases-with-join/#findComment-348167 Share on other sites More sharing options...
Barand Posted September 14, 2007 Share Posted September 14, 2007 What are your tablenames and column names in the 2 databases? Assuming the tables are [pre] database1.users database2.userinfo --------------- ------------------ user_id user_id username surname [/pre] Then the query would be <?php $sql = "a.username, b.surname FROM database1.users a INNER JOIN database2.userinfo b ON a.user_id = b.user_id"; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { echo $row['username'], ' : ', $row['surname'], '<br />'; } ?> However, I think the 2 databases need to be in the same server Quote Link to comment https://forums.phpfreaks.com/topic/69283-conecting-to-two-sep-databases-with-join/#findComment-348278 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.