Outline by Php.net, you can create a presistent database connection, but i am wondering why would I use this method when I could create a singleton class that instantiates the db connection and exposes it by some function?
Asked
Active
Viewed 163 times
0
-
I think the counter example you give in your question is not very clear. You might have not understood the properties of the persistent database connection. This has less to do how often you intantiate a PDO object. – hakre Jun 17 '17 at 13:57
-
Who do persistent connections have to do with singleton pattern? – Álvaro González Jun 17 '17 at 14:29
1 Answers
1
A non-persistent singelton connection (PDO) is getting closed at the end of the script (response). 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. A persistent connection can cause unwanted side-effects and security issues.
What are the disadvantages of using persistent connection in PDO

odan
- 4,757
- 5
- 20
- 49