php锁表

来源:互联网 发布:淘宝卖家账号 编辑:程序博客网 时间:2024/05/29 14:42

用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);

原创粉丝点击