1) Using the scenario "to write to the database after the decision", this is generally not a problem, but the concurrent access is not very good. Because the write (insert) takes time, assume that there are now two concurrent requests, (assuming that the first access is the last qualifying write request, according to logic, the second request should be illegal, cannot be written), and the second request queries to the data record that was not updated before the first request was successfully written. Because the record is not updated, it can also be judged. Finally, two requests are written to the data.
2) Workaround: Query the Lock table
Before I finish handling the storage, I will not let you check, so you can not judge the wrong?
3) Lock Table statement
LOCK TABLES tbl_name WRITE;
Note that this is a write!!.
Unlock:
UNLOCK TABLES;
Note: to query before the lock table (select), after the lock table, the process is able to continue querying, just lock the query of other processes
MySQL Query lock table