Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concurrent mutiuser access php+mysql

Tags:

php

mysql

innodb

Im going to develop Stock maintaining system using php+mysql. which will runs on server machine, so many users can update stock data. (in/out)

Im currently working on this system. I have following problems.

User A opens record “A”. ex- val=10
User B opens record “A”. ex - val=10
User A saves changes to record “A”. ex - val=10+2=12 (add 3 items, then stock should be 12)
User B saves changes to record “A”. ex - here i need to get record "A" value AS = 12, then B update val=12+3=15. (then add 3 items final stock will be 15)

In this example, User A’s changes are lost – replaced by User B’s changes.

I know mysql Innodb facilitate row level locking. My question is ,

is innodb engine do concurrent control ; and is this enough to (Innodb) to avoid "lost update" problem. or need to do extra coding to avoid this problem.

Is this enough please tell me how innodb works with my previous example. (lost update)

(sorry for my bad english)

thanks

like image 441
Thari Avatar asked Sep 05 '26 04:09

Thari


1 Answers

InnoDB allows concurrent access, so User A and User B could definitely be handling the same data. User A will update the row based on his/her data, then User B can do the same -- ultimately resulting in User A's loss of data.

You should consider an alternative, if every update is vital to keep. For example, if both users are updating a blog article, you could make a new table that holds all these edits. Both user's edits would be preserved, despite when they retrieved the article content. When the article is retrieved, you can check when the most recent edit occurred and retrieve that instead.

like image 173
Litty Avatar answered Sep 07 '26 18:09

Litty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!