...

View Full Version : Must one close a MySQL database?



RTrev
03-12-2007, 01:02 PM
I've got a little PHP/MySQL learning project where I'm simply storing links to sites, for display. One page shows the categories to choose from, and when the user makes a choice we jump to the next page which does a query on the category and displays all matching links.

People will be going back and forth between the two pages, which makes me want to open the database and table once and leave it open. The alternative is repeated opening/closing.. which must introduce quite a bit of overhead.

The problem is if the user simply leaves either page, which they presumably will at some point, the database will never be closed via an actual close statement.

What happens in a case like that? In my testing I can't find any downside to doing this, but I suspect there must be one.

Thanks,
Bob

guelphdad
03-12-2007, 02:09 PM
when your script exits then the database connection is closed by default.
You should also look into using persistant connections if you have not done so. that is in the php manual.

RTrev
03-12-2007, 02:21 PM
when your script exits then the database connection is closed by default.
You should also look into using persistant connections if you have not done so. that is in the php manual.

Thanks.. will check out the persistent connections. Appreciate the reply!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum