Lock mysql table with php

后端 未结 4 1148
长情又很酷
长情又很酷 2020-12-11 18:01

Script 1.

$query_ = \"lock tables test1 as test11 write\";
mysql_query($query);
$query_ = \"select * from test11\";
sleep(20);
$query_ = \"unlock tables\";
m         


        
4条回答
  •  春和景丽
    2020-12-11 18:34

    You have a misconception about what locks do. Locks to do not prevent other scripts from accessing data, instead locks affect the timing of when other scripts will access the data. When script 2 tries to access or modify data that it is not allowed to because of a lock, it will pause and wait for the lock to be released. After script 1 unlocks the table, script 2 will proceed and complete without any problems.

提交回复
热议问题