Toll Free Telephone: 800.385.8350 | Local: 262.671.2023 | Mon-Sat 12am-11:59pm

My Code Teacher

Red Cross
 
MyCodeTeacher Forum
September 04, 2010, 12:34:12 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: MyCodeTeacher forum launched!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Closing connection to SQL database  (Read 443 times)
Ronald Dear
Newbie
*
Posts: 19


View Profile Email
« on: April 18, 2010, 12:42:07 PM »

I've noticed that after a while working with tables in a database I sometimes get an error complaining of too many connections and then I can no longer even log into phpMyAdmin. After some digging I found out that you need to close a connection after you are done with it or else it remains open. I have been using the line:

include("sql.php");

in my php documents that use a db. In that document I have the lines:

$connection = mysql_connect(....)
$database = mysql_select_db(....., $connection)

My question is, do I need to have those lines in the document that uses the DB or can I just call

mysql_close($connection);

in the document that has the include("sql.php"); or do i actually have to have the connection and database lines in the file as well?

Thanks in advance for any help!
Logged
Masna
Administrator
Full Member
*****
Posts: 103



View Profile Email
« Reply #1 on: April 21, 2010, 09:28:55 PM »

Simply...

Code:
mysql_close();

...should work. Smiley

Anthony
Logged
Loren Hills
Newbie
*
Posts: 27


View Profile Email
« Reply #2 on: May 17, 2010, 11:04:13 AM »

I agree with Anthony. Also you may want to include it when ever you are done with a connection as is. This should prevent you from leaving connections open on accident. You could also include it in your footer file if you have one.
Logged

Thanks,
Loren
Linux and cPanel Instructor
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!