Locking Needed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • barrypalmer
    New Member
    • Oct 2007
    • 9

    #1

    Locking Needed

    PHP/mySQL website to allow multiple user editting records facility.

    Each record has 'status' '0'=awaiting edit;'1'=being editted;'2'=don e

    PHP makes mySQL query

    [CODE=mysql]SELECT * FROM table WHERE status=0;[/CODE]

    Then needs to quickly update status of this record to '1' to prevent someone else getting it.

    Or should it be [CODE=mysql]UPDATE table WHERE status=0 set status=1;[/CODE]
    But then how do I get the record data ?

    Does it really need a LOCK table before the SELECT & UPDATE then UNLOCK table ?
    Last edited by mwasif; Dec 14 '07, 12:48 PM. Reason: Added [CODE=mysql]/[/CODE] tags
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    You can perform this operation in this sequence
    1. LOCK table
    2. SELECT a record from table
    3. UPDATE the record (set status=0) using the Primary Key for the record you SELECTed in the previous step
    4. UNLOCK table

    Comment

    Working...