Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
May 2, 2005, 6:35 pm
rate this thread
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:
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
Re: DB- Too many connections - Should I be closing after each call?
See this page for description of that error:
Be sure to read the users' comments, there are some tips about this
error for PHP programmers.
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.
"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/too-many-connections.html for more
info related to getting this error in PHP scripts.
- » Americanas.com SALDO de TVs Com at 80% de Desconto (29798)
- — Newest thread in » MySQL Database Forum