rolandpish Posted February 21, 2010 Share Posted February 21, 2010 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 Link to comment https://forums.phpfreaks.com/topic/192792-singleton-and-transactions/ Share on other sites More sharing options...
Mchl Posted February 21, 2010 Share Posted February 21, 2010 ¿Does PHP creates a DB instance for each one of these 5 users? yes ¿Does PHP share the same DB instance for these 5 users? no ¿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? It won't. MySQL transactions are ACID compliant, which means they are dwsigned to handle such situations without errors. If requests of one user (A) will make it unable for another user (B) to perform his actions, the transaction for user B should be rolled back (note that you should put this in your code by yourself - query fails -> rollback) Link to comment https://forums.phpfreaks.com/topic/192792-singleton-and-transactions/#findComment-1015562 Share on other sites More sharing options...
rolandpish Posted February 22, 2010 Author Share Posted February 22, 2010 Thanks a lot for your reply Mchl. Those are great news! Then it will be no necessary to do modifications in my code. I really appreciate your help. Regards. Link to comment https://forums.phpfreaks.com/topic/192792-singleton-and-transactions/#findComment-1015868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.