Home > Backend Development > PHP Tutorial > 解决php停多人同时操作数据表

解决php停多人同时操作数据表

WBOY
Release: 2016-06-13 12:37:59
Original
814 people have browsed it

解决php下多人同时操作数据表

当同一时刻,多人对同一个表进行insert或者update的时候,往往会出现同一条数据出现好多次或者一些奇怪的问题,可以通过mysql的锁表机制来进行排队解决这个问题




php中插入数据之前锁表


// lock talbe write
        $sql = "LOCK TABLES alliance_perf WRITE";
        mysql_query($sql, $this->mysql->conn);
        unset($sql);
        
////////这里是数据insert操作
        
        // unlock table
        $sql = "UNLOCK TABLES";
        mysql_query($sql, $this->mysql->conn);
        unset($sql);

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template