Two databases, same server, different user to login

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.

I wouldn’t close your connection to db1 if you’re going to be using it again later in the script. Just open a connection to the second db when its needed.

Thanks for the reply cranial-bore.

I’d probably not need the connection again.

Interesting to see what other people do. Is this the way everyone does it or does it vary between programmers?