相关文章推荐
才高八斗的水煮肉  ·  节点:--openssl- ...·  2 年前    · 
温柔的大脸猫  ·  pytorch1.3.0+cuda10.0+ ...·  2 年前    · 
活泼的小熊猫  ·  mysql ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I've got an error in my php file. The error says 'PDOException' with message 'SQLSTATE[08004] [1040] Too many connections'. I have looked around and people says that i should change the max_connections on the mysql server. I did that, but it doesn't work.

Thanks in advance!

Are you closing the connection in your script after you are done with it, or do you keep spawning new PDO objects and new connections willy nilly? Fluffeh Jun 28, 2012 at 11:31 Persistent connections are not closed at the end of the script, but are cached and re-used when another script requests a connection using the same credentials. The persistent connection cache allows you to avoid the overhead of establishing a new connection every time a script needs to talk to a database, resulting in a faster web application. BUT this also results on too many connections being opened and not closed for a while so you might get that error. see example #4 Arustamyan G. Jun 28, 2012 at 11:45 Then that's not the problem. Everytime i nead a connection to the server i use a class called Server::connect(). can i close the connection like this: $pdo = Server::conect(); $pdo = null; user1156691 Jun 28, 2012 at 12:21 PDO documentation says that PDO connections are closed the way you do, but to be sure you should provide the code inside Server::conect() method. Arustamyan G. Jun 28, 2012 at 12:24

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .