skillednerd Posted January 23, 2011 Share Posted January 23, 2011 I have done select statements where you loop through all the records. But what I need to do is pull record from one database than insert parts of that record into the second. The issue I have is no knowing how to select a different db with out stopping the loop of the first. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/225436-how-to-php-loop-with-multiple-databases/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 23, 2011 Share Posted January 23, 2011 If you truly need to access two different databases at one time, you will need two different database connections and then simply use that connection link in the appropriate mysql_ statements. Quote Link to comment https://forums.phpfreaks.com/topic/225436-how-to-php-loop-with-multiple-databases/#findComment-1164133 Share on other sites More sharing options...
skillednerd Posted January 23, 2011 Author Share Posted January 23, 2011 ok thanks! Quote Link to comment https://forums.phpfreaks.com/topic/225436-how-to-php-loop-with-multiple-databases/#findComment-1164144 Share on other sites More sharing options...
DavidAM Posted January 24, 2011 Share Posted January 24, 2011 To access two different database servers you would need two different connections. But you can access multiple databases on the same server using a single connection. In fact, you can access multiple databases in a single query: SELECT * FROM dbOne.table1 AS T1 JOIN dbTwo.tableBravo AS T2 ON T1.coldID = T2.colFK You can also change the default database for a connection at any time using mysql_select_db() (or similar function). Inside your loop, just qualify the INSERT statement to the second database: INSERT INTO dbTwo.tableName (...) VALUES (...) Quote Link to comment https://forums.phpfreaks.com/topic/225436-how-to-php-loop-with-multiple-databases/#findComment-1164260 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.