I always thought it was always useful to close the database connection, regardless of the database / ORM, e.g. mysql_close (), Propel :: close (), etc.
As for one of my other question and some other research on the Internet, I found out an amazing person that most people actually recommend if you close the connection, since the connection always closes after the request.
However, I find these answers a bit difficult to digest. The reason is why all DB lib, ORM provide a private method? If it is, in every ORM / lib , it should be useful.
Can someone shed some light on under what circumstances should we use a closed method to close a connection to a database? and if these methods are not at all useful, why are they present there in all db libs / ORM?
EDIT
My conclusion
It was a good discussion between Bondye and Fluffeh, and it cleared my doubts about using a close connection. Thanks to both of them.
- If your script should last less than 100 ms, don't worry about closing the connection.
- BUT: if the script is expected to last longer and there is free time for the other between the last DB operation and the closing of the script by calling * close ().
It is really very difficult for me to accept one answer, since both answers are correct in their place. Just accept the answer with all the comments so that it stays on top. But +1 for both correct answers.
Kapil sharma
source share