I’m trying to do a simple lock that prevents any other requests from reading or writing a single table. The results of my code after both being typed into and executed in phpmyadmin:
LOCK TABLES mytable WRITE;# MySQL returned an empty result set (i.e. zero rows).
INSERT INTO mytable (field1, field2) VALUES ('21', '123123');# 1 row(s) affected.
The lock didn’t work and the insert did. Clearly not working correctly…what am I doing wrong? I’ve been pouring oer the MySQL docs and this seems like what they say to do…
Locks are there to prevent OTHER sessions from accessing the table while YOUR session is working on the table. There’d be no point in locks if putting a lock on a table locked your own code out as well.
You’d have to test it with TWO connections. One connection does the lock, the other connection tries to do the insert.
Doing it all within phpmyadmin does it over ONE single connection, and is not a valid test.