Home  >  Article  >  Backend Development  >  Solve the problem of multiple people operating data tables at the same time under PHP_PHP tutorial

Solve the problem of multiple people operating data tables at the same time under PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:19:131011browse

When multiple people insert or update the same table at the same time, the same piece of data often appears multiple times or some strange problems occur. This problem can be solved by queuing through the MySQL table lock mechanism.

Lock the table before inserting data in php
// lock talbe write
$sql = "LOCK TABLES alliance_perf WRITE";
mysql_query($sql, $this->mysql->conn);
unset($sql);
////////This is the data insert operation
// unlock table
$sql = "UNLOCK TABLES";
mysql_query($sql, $this->mysql->conn);
unset($sql);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532696.htmlTechArticleWhen multiple people insert or update the same table at the same time, the same piece of data will often appear. Many times or some strange problems can be solved through the lock table mechanism of mysql...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn