Home >Backend Development >PHP Tutorial >apache php mysql php lock table operation

apache php mysql php lock table operation

WBOY
WBOYOriginal
2016-07-28 08:30:081148browse

header('content-type:text/html;charset=utf8');

$Database = new PDO('mysql:host=127.0.0.1;dbname=iweb','user', 'Password');

//Execute the SQL statement to lock the userinfo table

$sql = "LOCK TABLES iwebshop_goods WRITE";

//The WRITE lock of the table blocks all other mysql query processes

$Database-> exec($sql);

//Perform update or write operation

$sql = "UPDATE iwebshop_goods SET `store_nums`=`store_nums`-1 WHERE store_nums>0 and id=1";

$Database-> ;exec($sql);

//After all write operations of the current request are completed, execute the unlock sql statement

$sql = "UNLOCK TABLES";

$Database->exec($sql);


The above introduces the lock table operation of apache php mysql php, including the content of apache php mysql. I hope it will be helpful to friends who are interested in PHP tutorials.

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