Hi!
I have a question about singleton and transactions in a mysql database.
Recently I built an application which uses PDO to access the mysql database and I'm using Singleton pattern to allow only one instance of the connection to the bd.
I use transactions in most of the database operations. So, let's show this scenario: 5 users in their own computers in 5 different pages of my application. They are ready to click a button that triggers operations (which use BD transactions).
¿Does PHP creates a DB instance for each one of these 5 users? or ¿Does PHP share the same DB instance for these 5 users?
¿How does Singleton handle the particular transaction for each user?
For instance, let's say that the 5 users click at the same time. ¿Could this possibly lead to errors on db operations?
I would really appreciate your help.
Regards
Singleton and transactions
Moderator: General Moderators
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: Singleton and transactions
5 Different users = 5 different connections.
Every user to access your page builds the singleton on page load, and destroy's it on page close.
Every user to access your page builds the singleton on page load, and destroy's it on page close.
Re: Singleton and transactions
Thanks a lot flying_circus. Those are great news!flying_circus wrote:5 Different users = 5 different connections.
Every user to access your page builds the singleton on page load, and destroy's it on page close.
Then it will be no necessary to do any changes on my code.
Regards