digjack
digjack

Reputation: 295

PHP about single instance connect mysql

In many php code of online, they use php single instance to connect mysql database. of course, they use pdo connection in the single instance. but i have a question about the database connection timeout. as we known, the single instance will destroy as we use it out, the connection will cut by the time . if we use the instance ten time, the connection will be establish and destroy ten times. that is not the result i want. Is there any methods to deal with the problem. I don't figure out that if it is wise to save the instance for some time. for example, save it in the memory.

Upvotes: 0

Views: 65

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157839

There is no problem like that.

It's hard to tell from your question what is your problem, but neither actually exists.

i have a question about the database connection timeout. as we known, the single instance will destroy as we use it out, the connection will cut by the time

Only if your script runs as a demon for considerable long time. but that's a very special case and it shouldn't be your concern for now.

if we use the instance ten time, the connection will be establish and destroy ten times. that is not the result i want.

It's OK.
PHP works this way. With every request PHP opens back all files or services that were used last time. That's how PHP works. So, don't worry about that either. Just keep coding and busy yourself only with real problems not imaginary ones.

Upvotes: 1

Related Questions