needs_upgrade Posted October 15, 2010 Share Posted October 15, 2010 Hello again guys! What if i have 2 databases, db1 and db2. i want to read raw data from db1 and match it's content with data from db2, then produce some information. How can i do it at the same time? I know that to be able to access mysql data, we have to use the mysql_connect() and mysql_select_db(). mysql_select_db() only allows to connect to single database. what should i do? thanks for your help in advance. Quote Link to comment https://forums.phpfreaks.com/topic/215947-connecting-to-two-2-databases-at-the-same-time/ Share on other sites More sharing options...
premiso Posted October 15, 2010 Share Posted October 15, 2010 mysql_connect returns a link, you will just assign that out and then use that link when querying IE: $db1 = mysql_connect('data', 'data', 'data'); mysql_select_db('database1', $db1); $db2 = mysql_connect('data2', 'data2', 'data2'); mysql_select_db('database2', $db2); mysql_query('SOME SQL STATEMENT', $db1); mysql_query('SOME OTHER SQL STATEMENT', $db2); For a rough example. If it is connecting to the same MySQL Server, you can just invoke the mysql_select_db after you queried the first database and change the database to the second one instead of opening a new connection. Quote Link to comment https://forums.phpfreaks.com/topic/215947-connecting-to-two-2-databases-at-the-same-time/#findComment-1122506 Share on other sites More sharing options...
needs_upgrade Posted October 15, 2010 Author Share Posted October 15, 2010 Thanks mate. It will solve my problem. Quote Link to comment https://forums.phpfreaks.com/topic/215947-connecting-to-two-2-databases-at-the-same-time/#findComment-1122515 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.