Jump to content


Photo

Closing the MySQL connection


  • Please log in to reply
3 replies to this topic

#1 archie

archie
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 13 August 2003 - 12:31 AM

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
Domain names are like girls; all the one\'s I like are allready taken...

#2 michael yare

michael yare
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationLondon, UK

Posted 13 August 2003 - 11:19 AM

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.

#3 archie

archie
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 14 August 2003 - 11:35 PM

Thanks Michael.

Just found this in the php manual:

Using mysql_close() isn\'t usually necessary, as non-persistent open links are automatically closed at the end of the script\'s execution


Domain names are like girls; all the one\'s I like are allready taken...

#4 michael yare

michael yare
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationLondon, UK

Posted 15 August 2003 - 10:59 AM

Good job.

I usually include a mysql_close() footer anyway, so I can add other footer information along with it (html anchors etc.).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users