I have two databases, primary and secondary. on the same page I need to take the data from second base, but without losing the connection to the first base.
Asked
Active
Viewed 49 times
1 Answers
2
You can make multiple calls to mysql_connect(), but if the parameters are the same you need to pass true for the '$new_link' (fourth) parameter, otherwise the same connection is reused.
so then you have
$dbh1 = mysql_connect($hostname, $username, $password);
$dbh2 = mysql_connect($hostname, $username, $password, true);
mysql_select_db('database1', $dbh1);
mysql_select_db('database2', $dbh2);
Then to query database 1, do this:
mysql_query('select * from tablename', $dbh1);
and for database 2:
mysql_query('select * from tablename', $dbh2);

Matheno
- 4,112
- 6
- 36
- 53
-
2you really should not recommend the usage of mysql_* functions. http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – thpl May 17 '13 at 10:02
-
I know, it's just that I still need to get used to it, and this was just an example. – Matheno May 21 '13 at 11:34