用于读写的锁表 [英] Lock table for reading and writing

查看:45
本文介绍了用于读写的锁表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用php锁表进行读写?这是我在没有运气的情况下尝试过的.

How to lock table for reading and writing with php? Here is what I tried without luck.

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

这是我得到的错误:

您的 SQL 语法有错误;检查手册对应于您的 MySQL 服务器版本以使用正确的语法在第 1 行的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.

你不能在没有别名的情况下为同一个表获取多个锁.阅读手册.

You can not acquire multiple locks for the same table without aliasing it. Read the manual.

这篇关于用于读写的锁表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆