Singleton and transactions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pish
Forum Newbie
Posts: 4
Joined: Sun Feb 21, 2010 1:25 am

Singleton and transactions

Post by pish »

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
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Singleton and transactions

Post by flying_circus »

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.
pish
Forum Newbie
Posts: 4
Joined: Sun Feb 21, 2010 1:25 am

Re: Singleton and transactions

Post by pish »

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.
Thanks a lot flying_circus. Those are great news!
Then it will be no necessary to do any changes on my code.

Regards
Post Reply