Persistent connection to the Mysql database [closed]

3

Hello, I would like to know if I have an open database connection (persistent connection) is better than I always close after a query?

    
asked by anonymous 31.07.2014 / 18:39

1 answer

5

That depends a lot. Several instances (Keep the connection open) can be useful if there is a great continuous demand, or if the control of access to the bank and operations supported (insert, alter, delete) is done by users of the bank, or even if the requests to the bank are distributed. In contrast, a single instance, in addition to being easier to manage, caters well to a reasonable number of users with sporadic requests (which is the case in many systems).

But you close and open the connection to the bank can have a remarkable cost in performance, since the resources spent (time and processing) to load the driver and access the bank several times can cause undesired slowness, especially if many consecutive requests are made.

You could do a Singleton to solve your case. Follow this guide here which is very good:

link

    
31.07.2014 / 18:46