Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 24-Feb-13 9:52am
Rate this: bad
good
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.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 310
1 CPallini 310
2 George Jonsson 269
3 Gihan Liyanage 255
4 OriginalGriff 245
0 OriginalGriff 4,903
1 CPallini 3,960
2 Sergey Alexandrovich Kryukov 3,474
3 George Jonsson 2,786
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web02 | 2.8.140905.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2014
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