Persistent connection to the Mysql database [closed]

Posted on

Question :

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


Answer :

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:



Leave a Reply

Your email address will not be published. Required fields are marked *