PDO and support the connection?

Hello!

There is a class for working with a database DB. In the designer, connect to the database (MS Access). The fact that a class instance is created in various parts of the code, and when displaying one page, it may be that >10 times the constructor is called (as I understand it, is created 10 different connections?). This leads to the fact that the queries run very long.
If you connect to the database with the key PDO::ATTR_PERSISTENT => true, the speed increases significantly, but this does not suggest to do (learned from experience, after 5 minutes locked some tables from a full script execution, as I understand it).
Actually, I would like to hear advice on how to get out of this situation.
September 18th 19 at 23:55
3 answers
September 18th 19 at 23:57
Solution
Well, you can also wrap the PDO in a static class or a singleton of some kind, which will connect to the database only if the connection is not yet installed, either use the already established connection.
Thank you! Say, static classi - bad, but had to do so. - Savion_Kozey commented on September 19th 19 at 00:00
: Bad use them without thinking, and generally mindlessly to do something bad:) But in this case, the use is justified. - ari_Ra commented on September 19th 19 at 00:03
September 18th 19 at 23:59
To create an instance only once.
September 19th 19 at 00:01
The fact that a class instance is created in various parts of the code

What's the problem? Do NOT CREATE an instance of the class for working with DB in various code sections
Okay. There are a dozen classes, methods that need to retrieve data from the database using the actual DB class. How to get out of this situation? - Savion_Kozey commented on September 19th 19 at 00:04
Is it necessary each time to re-create? - ari_Ra commented on September 19th 19 at 00:07
see previous question on the PDO tag - there is a man in advance attended to this issue - Savion_Kozey commented on September 19th 19 at 00:10

Find more questions by tags Microsoft AccessPHP PDOPHP