thefreebielife Posted May 24, 2007 Share Posted May 24, 2007 i cant figure out how to do this. they are both on the same server, but with different names, logins, etc. does anyone have sample code or any help. thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/52891-getting-info-from-2-separate-databases-to-display/ Share on other sites More sharing options...
Barand Posted May 25, 2007 Share Posted May 25, 2007 <?php $con1 = mysql_connect('localhost'); mysql_select_db('test'); /** * using default 'test' db */ $res1 = mysql_query("SELECT * FROM sales"); while ($row = mysql_fetch_row($res1)) { echo join(' | ', $row) . '<br>'; } /** * using table from 'test2' db */ $res2 = mysql_query("SELECT * FROM test2.city"); // specify db.table while ($row = mysql_fetch_row($res2)) { echo join(' | ', $row) . '<br>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52891-getting-info-from-2-separate-databases-to-display/#findComment-261204 Share on other sites More sharing options...
Barand Posted May 25, 2007 Share Posted May 25, 2007 Same again, but with different logins (untested) <?php $con1 = mysql_connect('localhost','user1', 'pwd1'); mysql_select_db('test', $con1); $con2 = mysql_connect('localhost','user2', 'pwd2'); mysql_select_db('test2', $con2); /** * using 'test' db */ $res1 = mysql_db_query("test", "SELECT * FROM baagriddata"); while ($row = mysql_fetch_row($res1)) { echo join(' | ', $row) . '<br>'; } /** * using table from 'test2' db */ $res2 = mysql_db_query("test2", "SELECT * FROM city"); while ($row = mysql_fetch_row($res2)) { echo join(' | ', $row) . '<br>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52891-getting-info-from-2-separate-databases-to-display/#findComment-261217 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.