//sql原生锁表
mysql_connect('localhost','root',''); //连接数据库
mysql_select_db('test'); //选择数据库
mysql_query('lock table a wriet'); //加写锁
$sql = 'select * from a';
$data = mysql_query($sql); //执行
$res = mysql_fetch_array($data); //遍历
$id = $res[0];
mysql_query("update a set id=$id"); //带条件查询
mysql_query('unlock tables'); //解锁