Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 13th, 2007, 05: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
Reply


Thread Tools
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 11:32 AM
ASP / ADODB - How to close connection? hamproof Classic ASP Databases 4 August 24th, 2007 02:43 PM
sqldatareader close connection mdonner BOOK: Beginning ASP.NET 1.0 2 July 5th, 2007 05:50 AM
Command Object -- How to close db connection? wolfpack391 Classic ASP Databases 4 July 31st, 2004 06:28 AM
Open/Close SQL Connection within every method? flyin ADO.NET 8 May 18th, 2004 08:19 AM



All times are GMT -4. The time now is 01:35 AM.


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