Conexões Clonadas

Asked

Viewed 97 times

2

I wonder if there is how to create only a connection to the database to perform the tasks. With each Action executed, a connection with the Database is created and at the end of the Action execution, the connection is closed. Then, when it is necessary to execute an Action within another, two connections are opened in addition to the one that was opened for the first query to the database, thus creating several connection clones.

I wonder if there’s any function that can solve this and how to use it. If you need some code to give a better understanding of what I need I put it here.

  • Are you using any framework?

  • 1

    Use the Yii framework. And the database is Postgresql

1 answer

0


Usually you use the pg_connect resource for all connections. But you don’t necessarily have to follow this rule. You can create a connection for each "action".

I would do different: instead of a connection for each action I would use a transaction per action. Code here.

Using Yii, you will not directly use PHP’s postgres functions, but the logic is the same. You have here the way to do it with Yii.

  • Okay! Thank you for the answer. I’ll check on that!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.