0

I'm working on some large software that has a current database connection open that connects to one database, but unfortunately it doesn't use the link identifier in it's query calls.

Now I had to open a connection to another database; this works fine, however all calls to database functions now seem to use the second connection I opened (they use different arguments).

Is there any way to avoid this and get the queries to go back to using the first connection opened or will I have to add a link identifier to all the other calls as well?

Can I just close the second connection and then it will go back to using it or not?

I know I can avoid opening a second connection by using listing the db in the query as well, but I don't really want both databases to use the same credentials.

Brett
  • 19,449
  • 54
  • 157
  • 290

1 Answers1

0

Found this tidbit from the php docs..

Note that the manual is slightly misleading it states :-

"Sets the current active database on the server that's associated with the specified link identifier. Every subsequent call to mysql_query() will be made on the active database."

The 2nd statement is not true or at best unclear.

mysql_query() manual entry actually correctly states it will use the last link opened by mysql_connect() by default.

Thus if you have 2 connections you will need to specify the connection when calling mysql_query or issue the connect again to ensure the 1st database becomes the default, simply using mysql_select_db will not make the 1st database the default for subsequent calls to mysql_query.

Its probably only apparent when the two databases are on different servers.

http://www.php.net/manual/en/function.mysql-select-db.php#108375

So looks like I will have to run another connection to the first database when I am done with the second one.

Brett
  • 19,449
  • 54
  • 157
  • 290