views:

29

answers:

1

Hi,

If I were designing a new system, should I have each function open and close the mysql connection as and when needed OR should I form one connection and keep that as a "globally accessible variable" for that browser session?

Why is it a bad idea, if indeed it is?

A: 

Assumning we're speaking about a web application here:

It's usually better to have a single connection for processing entire request (not session). Less overhead, less connections used from connection pool (so more clients can connect simlutaneously), easier to work with transactions etc. Only drawback I can see, is it can be a bit more difficult to code for that.

Mchl