Solve the problem of stopping multiple users in php and simultaneously operating data tables

Source: Internet
Author: User
When multiple users operate data tables in php at the same time and perform insert or update operations on the same table, the same data may occur many times or some strange problems, the mysql lock table mechanism can be used for queuing to solve this problem. before inserting data in php, the lock table // locktalbewrite & nbsp; & nbsp solves the problem of simultaneous data table operation by multiple users in php.

When multiple people insert or update the same table at the same time, the same data may occur many times or some strange problems, the mysql lock table mechanism can be used for queuing to solve this problem.




Lock table before inserting data in php


// Lock talbe write
$ SQL = "LOCK TABLES alliance_perf WRITE ";
Mysql_query ($ SQL, $ this-> mysql-> conn );
Unset ($ SQL );

/////// Here is the data insert operation

// Unlock table
$ SQL = "UNLOCK TABLES ";
Mysql_query ($ SQL, $ this-> mysql-> conn );
Unset ($ SQL );

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.