php数据库连接错误

php数据库连接错误

问题描述:

im hoping someone can help me quickly with a question i have.

As site i have build is occasionally returning with the error

Warning: mysqli::mysqli() [mysqli.mysqli]: (08004/1040): Too many connections in

Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in

Now at first i thought this was happening as i hadent closed the connection at the end of each page, now i get the connection like this at the beginning of a page / script

$conn = new mysqli($host, $username, $password, $database);

and at the very end call

$conn->close();

Also i close any result sets i have open.

Looking at my log files around the time i accessed the site today and saw this error, I accessed about 12 o clock and at first the page wouldnt even load, then it gave me this error. before that one person visted around 11:30 and then 10:30, not exactly heavy traffic.

The host I have gone with is very quiet and there is no way to get in contact with them, and ignoring any support emails, i thought maybe as now i hear they are not very good this could be an issue with a badly set up shared mysql server?

Any thoughts or suggestions would be amazing as i need to sort this out!

Thanks in advance!

我希望有人可以快速帮我解决一个问题。 p>

由于网站我的构建偶尔会返回错误 p>

警告:mysqli :: mysqli()[mysqli.mysqli] :( 08004/1040): p>中的连接太多

警告:mysqli :: query()[mysqli.query]:无法获取mysqli p>

现在我起初认为这是因为我关闭了 每个页面末尾的连接,现在我在页面/脚本的开头得到这样的连接 p>

$ conn = new mysqli($ host,$ username,$ password, $ database); p>

并在最后调用 p>

$ conn-> close(); p> 我也关闭了我已打开的任何结果集。 p>

查看我今天访问该网站时的日志文件并看到此错误,我访问了大约12点钟,并且一开始 页面甚至不会加载,然后它给了我这个错误。 在那之前,一个人在11:30左右和10:30之间访问,并不是非常繁忙的交通。 p>

我去过的主人非常安静,没有办法接触到 他们,并忽略任何支持电子邮件,我想也许现在我听说他们不是很好这可能是一个设置错误的共享mysql服务器的问题? p>

任何想法或建议将 太棒了,因为我需要解决这个问题! p>

提前致谢! p> div>

It sounds like the MySQL server is being shared by too many accounts, as that error means that the server's max_connections setting has been exceeded. It could be that there are several other high-traffic customers that are taking up the connections (this is a shared MySQL server, I take it?)

I'm fairly sure that PHP automatically closes resources at the end of the request (although it's always best to explicitly close your connections etc. anyway) so I wouldn't think it's your script keeping connections open.

You'll need to keep on at your hosting provider, I'm afraid, or consider moving providers. Also try to keep a log of when the errors occur and for how long, as you'll need that as evidence if they refuse to acknowledge there's a problem.

You can also refer your provider to this page: http://dev.mysql.com/doc/refman/5.1/en/too-many-connections.html.