V
V
vista1x2015-03-03 16:57:25
PHP
vista1x, 2015-03-03 16:57:25

PDO and connection support?

Hello!
There is a class for working with a DB database. In the designer I connect with a DB (MS Access). The fact is that an instance of the class is created in different parts of the code, and when displaying one page, it may happen that the constructor is called more than 10 times (as I understand it, 10 different connections are created?). This causes queries to take a very long time to complete.
If you connect to the database with the key , then the speed increases many times, but this is not advised to do (I was convinced by experience that after 5 minutes of work some tables were blocked due to incomplete execution of the script, as I understand it). Actually, I would like to hear advice on how to get out of this situation. PDO::ATTR_PERSISTENT => true

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry S, 2015-03-03
@vista1x

Well, you can wrap PDO in a static class or some kind of singleton that will connect to the database only if the connection has not yet been established, or use an already established connection.

M
Melkij, 2015-03-03
@melkij

Create an instance only once.

F
FanatPHP, 2015-03-03
@FanatPHP

The fact is that an instance of the class is created in various parts of the code.

What problems? DO NOT create an instance of the class to work with the database in different parts of the code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question