Jump to content

Closing the MySQL connection


archie

Recommended Posts

Hi there.

 

Would I be right in believing that one should close a MySQL connection after one has finished using it? eg if your page adds members to database, at the beginning of the page you would open the connection, then you would carry out the relevent quieries, then, finally, close the connection?

 

If so, is the following possible?

 

Store all the database info (username, password etc) in db.inc.php. Also put in this file the command to open the DB connection.

 

In the file footer.inc.php (which would be added to all pages on the site) have a test to see if a DB connection is open, and if so, close it.

 

Is this possible? Can one test for an open connection? (if so, how? :) )

 

Secondly, is this the most efficient way of doing this. The site I have in mind will be making very frequent use of the database; is it possible (and advisable) to keep the DB connection open?

 

Sorry if this sounds complicated, or just non-sensical. Thanks in advance for your help

Link to comment
Share on other sites

What you suggest is very possible and good practice.

I can confirm that including connection and closing statements works well.

 

I am only just now assessing the impact of user sessions and open connections.

 

I have had a look at a PHP reference book and cannot find any way of testing the connection, yet.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.