php - InnoDB locking a row to prevent multiple concurrent sessions from reading it -
i'm using innodb.
i have table a
id | data 1 | 2 | else
table b
user_id | data 1 | null
my program reads row table , updates table b, deletes row table after update statement.
is possible 2 users (2 different concurrent sessions) read same row table a? how can avoid that?
that's program
$core = database::getinstance(); $q = $core->dbh->prepare("select * `tablea` limit 1"); $q->execute(); $result = $q->fetch(); $q = $core->dbh->prepare("update `tableb` set `data` = ? `user_id`= ?"); $q->execute(array($result['data'],$id));
// how prevent second user reading same row before next statement gets executed
$q = $core->dbh->prepare("delete `tablea` `id`= ?"); $q->execute(array($result['id']));
you can select ... update
puts exclusive lock onto row (at least if transaction isolation level set reasonable).
this works if storage engine of table innodb. have execute queries inside of same transaction (so execute begin
query @ beginning , commit
@ end).
Comments
Post a Comment