469,963 Members | 2,196 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

DB- Too many connections - Should I be closing after each call?

Hi There,
Been working in a PHP / MySQL project I took over code development for.
Today when testing new changes suddenly started getting "Failed to
connect to the database" errors.

When logged into phpmyadmin it said:

Error
MySQL said:

Too many connections
Now does this mean that becuase the website I'm working on uses shared
webhosting, that there could be other people viewing websites on the
same server and it has just got too busy?

Or could matters be made worse by the fact that I notice in the code I
took over the original coder never seemed to expicitly close a
connection to the DB.

For example, he would have a funtion in a header file that would open /
connect to DB run an SQL query and then exit. Never an explicit close.
Is this very bad? He was a compotent programmer so I assumed that the
connectoions must close themselves, but now with this error I thought I
better check.

Kind regards

Jul 23 '05 #1
1 2049
Gr*************@lycos.co.uk wrote:
MySQL said:
Too many connections
See this page for description of that error:
http://dev.mysql.com/doc/mysql/en/to...nnections.html
Be sure to read the users' comments, there are some tips about this
error for PHP programmers.
Now does this mean that becuase the website I'm working on uses shared
webhosting, that there could be other people viewing websites on the
same server and it has just got too busy?
That'd be my first guess. The default maximum number of connections on
a new MySQL installation is 100. This is determined by a startup option
for mysqld, and the system administrator is the one who can alter this
value. See the above web page I referenced.

You should talk to your hosting service about raising the maximum number
of connections on their MySQL server, if it is set too low.
For example, he would have a funtion in a header file that would open /
connect to DB run an SQL query and then exit. Never an explicit close.
Is this very bad?


http://us4.php.net/manual/en/function.mysql-close.php

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

So it depends on whether the connections are opened as regular
connections or persistent connections. In the case of PHP, it's the
difference between using mysql_connect() or mysql_pconnect().
See users' comments on
http://dev.mysql.com/doc/mysql/en/to...nnections.html for more
info related to getting this error in PHP scripts.

Regards,
Bill K.
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Eben Goodman | last post: by
3 posts views Thread by john bailo | last post: by
1 post views Thread by hananiel | last post: by
37 posts views Thread by Joshua Ruppert | last post: by
2 posts views Thread by osmarjunior | last post: by
11 posts views Thread by atlaste | last post: by
6 posts views Thread by Steve Ricketts | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.