Monday, 19 August 2013

lock tables sql+php PDO

lock tables sql+php PDO

I want to lock a table before doing the action on the table in PDO, so two
users will not be able to do the same action in the same time.
I tried as follow:
$this -> link ->beginTransaction();
$this -> link ->exec('LOCK TABLES `MYTABLE` WRITE;');
//do something...
$this -> link ->exec('UNLOCK TABLES');
$this -> link ->commit();
but if two users try this query, they both stack. what I do wrong?
thanks!!

No comments:

Post a Comment