Page 1 of 1

MYSQL Select/Update Lock Question

Posted: Wed Oct 25, 2006 11:04 am
by tbrown1
Ok the answer to this quesiton is probably obvious but it is bothering me.
So I am wiriting a script that many people will be adding data to at the same time.
The script basically runs a select statement get a row of data take one cell out then adds a value to the value from that cell and then runs an update statment to put that new data in the database.
My worry is what happens if two people do this at the same time and there select statments both run before one of the users update statement the second person will then be adding to a smaller number then they should be and messing up the data.
Is this a concern or is there automatic locking in php and mysql that will not allow this to happen.
If there isn't should I use something like LOCK TABLE X WRITE or something to that effect?

Posted: Wed Oct 25, 2006 11:26 am
by volka
tbrown1 wrote:The script basically runs a select statement get a row of data take one cell out then adds a value to the value from that cell and then runs an update statment to put that new data in the database.
Probably you do not need to select the value.

Code: Select all

UPDATE tablename SET fieldname=fieldname+4711 WHERE id=1234

Posted: Wed Oct 25, 2006 1:11 pm
by tbrown1
Thanks that worked