is PHP SQL sent to MySQL for one piece of execution?
If there are two updated SQL at the same time, are all operations the same row of data, then the two SQL is how to execute, one after the execution of a bar?
If it was executed successively, would it be understood that the automatic lock table was performed when the SQL was executed?
There is also the question:
I used to use MyISAM to appear such a problem, the application scenario is: A and B users send a message (Web Office chat box Ajax), A to B each message, a new record in the message table (unread message marked), and then at the same time B unread message +1, and b every few seconds Ajax requests to see if there is a new unread message in the message table, there is a fetch, marked as read the message, and then the unread field minus the number of unread messages, so that the design is not a problem, but if the message and refresh the message quickly millisecond then the problem, with JS analog Click, the problem is , and a stop sending messages, B user's unread field unexpectedly is not 0, originally good, why send message joy like this, this let me collapse, this also had, if the amount of money that is not finished Ah, this question is what reason?
Reply content:
is PHP SQL sent to MySQL for one piece of execution?
If there are two updated SQL at the same time, are all operations the same row of data, then the two SQL is how to execute, one after the execution of a bar?
If it was executed successively, would it be understood that the automatic lock table was performed when the SQL was executed?
There is also the question:
I used to use MyISAM to appear such a problem, the application scenario is: A and B users send a message (Web Office chat box Ajax), A to B each message, a new record in the message table (unread message marked), and then at the same time B unread message +1, and b every few seconds Ajax requests to see if there is a new unread message in the message table, there is a fetch, marked as read the message, and then the unread field minus the number of unread messages, so that the design is not a problem, but if the message and refresh the message quickly millisecond then the problem, with JS analog Click, the problem is , and a stop sending messages, B user's unread field unexpectedly is not 0, originally good, why send message joy like this, this let me collapse, this also had, if the amount of money that is not finished Ah, this question is what reason?
associated with the storage engine. Simply put, MyISAM is a table lock, InnoDB is a row lock. For details, refer to the MySQL manual: https://dev.mysql.com/doc/refman/5.5/en/locking-issues.html
You need to look at the introduction of database transactions. http://blog.csdn.net/wang_cir/article/details/6227155
This involves the concept of lock-optimistic lock, pessimistic lock. See the details. Optimistic lock handling is generally used.