There is a need to check whether an entry exists with certain data in the table.
Then in php, depending on the result, write data to another table, or to the same one.
Thus I do the following:
- In the php-script created a connection to the database.
Trash the table
LOCK TABLES `table1` WRITE, `table2` WRITE
I do sampling and all necessary actions.
Do unlock
UNLOCK TABLES
I close connection with a DB.
How can I check the performance of the lock?
I had two options:
Remove unlock from the php script and close the connection. Run the script twice in a row. I thought that the second time the sample did not work because of the first lock, but for some reason it worked. I can assume that due to the fact that once the script first lok the tables, then, starting the second time the script, I cancel the previous lock (because the repeated lock removes all previous locks), but, on the other hand, At the beginning of the script, a new connection to the database is created, and because of the new lock, the unlock should not occur.
Remove unlock from php script and close connection. Run the script. Query the table in phphMyAdmin. Here, too, everything went well, i.e. The request was executed despite blocking. Perhaps sql so smart and he unlocks the table?
Where is the guarantee that the lock / unlock still works? How to check it? Perhaps the type of table affects the work of the lock, or something else?