Jump to content

Connecting to two (2) databases at the same time


needs_upgrade

Recommended Posts

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.