开发者

how to solve Too many connections in mysql error?

开发者 https://www.devze.com 2023-03-10 09:02 出处:网络
I have a php application. There is a lot of database opera开发者_JAVA技巧tion and i do mysql_connect() to open connection. Do I have to close the connection manually?In general, after script execution

I have a php application. There is a lot of database opera开发者_JAVA技巧tion and i do mysql_connect() to open connection. Do I have to close the connection manually?


In general, after script execution the connections should close automatically. However in some cases (e.g. like yours) you have no other way but to do it manually (make mysql_close($connection) to be the last line of your script).

Alternatively, consider using mysql_pconnect() to have persistent connection, which doesn't close after script completion, and is (implicitly) reused on the next request.


Yes. But you do mysql_connect() many times. you can keep it in seperate file and include where ever needed.


Increase the number of allowable connection in mysql settings should do the trick i guess. But before that make sure on each page you are only opening the mysql connection once. At the end of the script the connection should automatically be closed, so no you dont really have to close it manually.


Use singleton to keep just one open connection on each page.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号