php锁表

时间:2023-09-12 18:53:02

用PHP实现mysql锁表

mysql锁表,是利用相关的SQL语句

//执行SQL语句 锁掉userinfo表

$sql = "LOCK TABLES userinfo WRITE";

//表的WRITE锁定,阻塞其他所有mysql查询进程

$Database->execute($sql);

//执行更新或写入操作

$sql = "UPDATE userinfo SET `correct_num`=`correct_num`+1 WHERE stat_date='{$current_date}'";

$Databaser->execute($sql);

//当前请求的所有写操作做完后,执行解锁sql语句

$sql = "UNLOCK TABLES";

$Database->execute($sql);