Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 13th, 2007, 04:25 AM
Registered User
Join Date: Sep 2007
Location: , , Sweden.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default When should you close the database connection?

When I learned PHP/MySQL from a friend he always closed the database connection after every query he made, but now I have read "Professional PHP5" and it says that opening a database connection takes more resources then all but the most complex queries.

I have built a database abstraction layer with the code from chapter 8 but changed from PostgreSQL to MySQL. I didn't use anything from the PEAR DB section either, except I added some function for selecting one row and I also added the singelton design pattern.

So now when I use my class I open a connection get all the stuff I need from the database and when the page is loaded the destructor closes the connection. But then I heard from other sources that leaving a connection open that long wont be good if you have a lot of visitors. Whats worse having connections open while you load the whole page or opening and closing a connection almost after every query? And is there sometime when one or the other is better?

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
close sql connection MunishBhatia ASP.NET 2.0 Professional 3 September 27th, 2007 10:32 AM
ASP / ADODB - How to close connection? hamproof Classic ASP Databases 4 August 24th, 2007 01:43 PM
sqldatareader close connection mdonner BOOK: Beginning ASP.NET 1.0 2 July 5th, 2007 04:50 AM
Command Object -- How to close db connection? wolfpack391 Classic ASP Databases 4 July 31st, 2004 05:28 AM
Open/Close SQL Connection within every method? flyin ADO.NET 8 May 18th, 2004 07:19 AM

All times are GMT -4. The time now is 06:22 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.