Click here to Skip to main content
12,896,175 members (53,110 online)
Rate this:
Please Sign up or sign in to vote.
See more: PHP MySQL connection
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 24-Feb-13 9:52am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

It is preferred to Open and Close the Connection each time you required.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100