Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi all
i have a some php function that work with mysql database

what is a best location for close database connection ?

please help me

thanks a lot
Posted

The question is true for all technology for example .NET, PHP etc. When required for execute any database command/query then you should open database connection and after getting result you should close that connection. Only problem area you can find that is connected resultset fetching issue. In .NET like datareader. You can not close connection until you finish to read datareader object. If same type of return object there in PHP then after finish to read that object then you close it. Always need to remember that database open connection time should as shorter as possible.
 
Share this answer
 
v2
It is preferred to Open and Close the Connection each time you required.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900