php - 锁表读写

标签 php mysql

php如何锁定表读写?这是我在没有运气的情况下尝试过的方法。

mysql_query("LOCK TABLES table WRITE;");
mysql_query("LOCK TABLES table READ, WRITE;");
mysql_query("LOCK TABLES table READ WRITE;");

这是我得到的错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WRITE' at line 1

最佳答案

mysql_query("LOCK TABLE table WRITE"); // you might think it's here
mysql_query("LOCK TABLE table READ, table AS t2 WRITE"); // <- but the error is here
mysql_query("LOCK TABLES table READ, table as t2 WRITE"); // <- ...and here.

如果没有别名,您不能为同一个表获取多个锁。 Read the manual .

关于php - 锁表读写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7981688/

相关文章:

php - 如何在 PHP 中重新格式化日期时间字符串?

具有 2 个值的 PHP 开关

mysql - 聊天系统的数据库设计

php - $_POST 在 php5.6 中为空

php - 由于(未知)原因,未显示通过查询从数据库中检索到的多个复选框值

mysql - 复杂的 CakePHP 查询重构

Java从mysql数据库错误填充jcombobox

powershell - MySQLDUMP与CMD/Powershell的区别

php - 简单的 PHP MySQL 查询分组任务

php - 从抽象类中的静态函数获取类名