DBMNG数据库管理与应用

抓住自己最有兴趣的东西,由浅入深,循序渐进地学……
当前位置:首页 > MySQL > 应用案例

Mysql数据库加锁与解锁

转自:http://www.pai7.cn/article.asp?id=359

SQL语句:

LOCK TABLES tablename WRITE;
LOCK TABLES tablename READ;
Insert INTO assignment VALUES (1,7513,'0000-00-00',5),(1,7513,'2003-01-20',8.5);
UNLOCK TABLES;

对于多个用户同时提交表单,并且同时向数据库中得到表单ID,我是这样解决的:

mysql_query("lock tables po read");
mysql_query("lock tables po write");

mysql_query("update po set id=id +1"));// increase po id

$sql = "Select id FROM po";
$result = mysql_query($sql);
if ($row = mysql_fetch_assoc($result)) {
    echo $row["id"]; // this order will use this id
}

mysql_free_result($result);
mysql_query("unlock tables"); 
本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号