LOCK table for READ MYSQL

I want to lock a specific table for reading, but when I requested

   mysql_query("LOCK TABLES unique_voucher READ");

into the database, it allows me to read only this table, but not other tables.

Is it possible to lock this particular table ONLY and does not allow users to query this table before completing any process?

(this is because I keep the counter, and if many users connect at once, they can get ambiguous numbers, so until one user is ready with one process, I want to block reading for the table)

+3
source share
1 answer

, , , . .

http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html:

", , , , LOCK TABLES. , , , , ., t2, LOCK TABLES:"

mysql> LOCK TABLES t1 READ;
mysql> SELECT COUNT(*) FROM t1;
+----------+
| COUNT(*) |
+----------+
|        3 |
+----------+
mysql> SELECT COUNT(*) FROM t2;
ERROR 1100 (HY000): Table 't2' was not locked with LOCK TABLES
0

All Articles