Page 1 of 1

closing database connection calls to mysql

Posted: Thu Jun 23, 2005 4:36 pm
by CincoPistolero
I took over the management of php site running mysql. The site is currently getting "reached maximum connections errors" The original programmer said that he didn't close out any of his sql calls. So I tried the below code in a footer. Is this correct.

<?php mysql_close();?>

Posted: Thu Jun 23, 2005 4:44 pm
by nigma
In the future please do not post your question in multiple forums. I've deleted your post in Databases.

And yes, that will close a mysql connection. See below for more info.

http://php.net/mysql_close

Posted: Thu Jun 23, 2005 4:50 pm
by CincoPistolero
I manange a site that has been working fine since I took over a few weeks ago. I've only made text changes, and at 10am this morning the site gets the following error:

WARNING: mysql_connect(); User ***** has already more than m'max_user_connections' active connections in ../../../database.php line 6
Unable to connect.

The guy who originally created the site never coded <?php mysql_close(); ?> but it is my understanding that closing isn't necessarily needed. I added the closing statement to the footer file and uploaded it, but I still get the above error. Any suggestions? :!:

Posted: Thu Jun 23, 2005 4:56 pm
by CincoPistolero
Sorry about the database post, I wasn't sure which forum it belonged in, and thanks. I figured it out. The mysql_connection was set in a variable so I had to put that in my close string.

Posted: Thu Jun 23, 2005 5:53 pm
by nigma
Glad you figured it out. Don't worry about the multiple post, as long as it doesn't happen again we're cool 8)

Posted: Thu Jun 23, 2005 6:20 pm
by John Cartwright
From his yet another double post
if i have four select statements on a php page, do I need to close the sql connection for each of those calls or can I just close it once at the end of the page.

Posted: Thu Jun 23, 2005 6:21 pm
by John Cartwright
Close your connection at the end of your page, and mysql_free_result() after your done with the results, instead of keeping it in memory.