PHP mysql concurrency problem?

Source: Internet
Author: User
Tags mysql manual php mysql
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.