Click here to Skip to main content
11,490,566 members (37,749 online)
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 10: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 520
1 Andy Lanng 233
2 Sascha Lefèvre 210
3 OriginalGriff 188
4 Maciej Los 160
0 Sergey Alexandrovich Kryukov 9,713
1 OriginalGriff 8,475
2 Sascha Lefèvre 3,544
3 Maciej Los 3,106
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2015
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