简体   繁体   English

php数据库连接错误

[英]php database connection errors

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 警告:mysqli :: mysqli()[mysqli.mysqli] :( 08004/1040):连接太多

Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in 警告:mysqli :: query()[mysqli.query]:无法获取mysqli

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); $ conn = new mysqli($ host,$ username,$ password,$ database);

and at the very end call 并在最后的电话

$conn->close(); $ conn->接近();

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. 看看我的日志文件,我今天访问该网站时看到了这个错误,我访问了大约12点钟,起初页面甚至没有加载,然后它给了我这个错误。 before that one person visted around 11:30 and then 10:30, not exactly heavy traffic. 在那之前,一个人在11:30到10:30之间访问,并没有完全交通繁忙。

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? 我去过的主人非常安静,没有办法与他们取得联系,并且无视任何支持电子邮件,我想也许现在我听说他们不是很好,这可能是一个问题,设置得很糟糕mysql服务器?

Any thoughts or suggestions would be amazing as i need to sort this out! 任何想法或建议将是惊人的,因为我需要解决这个问题!

Thanks in advance! 提前致谢!

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. 这听起来像MySQL服务器被太多帐户共享,因为该错误意味着已超出服务器的max_connections设置。 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?) 可能有其他几个高流量客户正在接受连接(这是一个共享的MySQL服务器,我接受了吗?)

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. 我很确定PHP会在请求结束时自动关闭资源(尽管最好明确地关闭你的连接等等)所以我不认为这是你的脚本保持连接打开。

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 . 您也可以将您的提供商引荐到此页面: http//dev.mysql.com/doc/refman/5.1/en/too-many-connections.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM