Jump to content

More than one database connection ??


johnsmith153

Recommended Posts

On some occasions I need to connect to a second and third database in the same script (maybe 5% of scripts have at least a second connection).

 

Usually I would just select the new database. However, my host requires different users to be created for each database.

 

What is the best way to do this?

 

Close current connection (say db1) and open new (say db2) OR keep all open, creating 2nd and 3rd connections.

 

I am happy with the design of my database, and don't want to merge all these tables into one db.

 

Overall I am still happy with my host, so I'd rather not change.

Link to comment
Share on other sites

It would be a case of mainly using database 1 which holds 70 or so different tables.

 

Occasionally database 2 will be used (holding lots of financial account information / transactions for lots of customers).

 

Usually I'd do all db1 queries then all db2 - as swopping back and forth would be pretty crazy I suppose.

 

I just need to know if it is better to open a new connection or close the existing. Can't be a big difference but does it take time to close one? I'm also aware of the limit of 500 connections per user, which isn't an issue at the moment but could be one day.

 

I use a couple of stored session values to query the tables in db2, so a JOIN query is not required. It's pretty rare that db2/3 are used.

 

There would be occasions where db3 is used, and sometimes (rarely) all three together.

Link to comment
Share on other sites

Thanks for the reply thorpe. The last time you said this I had forgotten the problem with my web host requiring a different user to be setup for each database.

 

This question is the first time I mention this.

 

Do I?

 

(a) Connect to db1, perform various queries, CLOSE, then connect to db2 and perfrom queries.

 

OR

 

(b) Connect to db1, perform various queries. Then connect to db2 without closing db1 and perfrom queries on db2.

 

I suppose the key thing is: does it take time to close a connection?

 

I doubt it's a major difference, but helps to do it the right way.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.