Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 13th, 2007, 04:25 AM
Registered User
 
Join Date: Sep 2007
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?






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





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