Home  >  Article  >  Backend Development  >  nginx - Transactions about phpmysql

nginx - Transactions about phpmysql

WBOY
WBOYOriginal
2016-08-04 09:20:591165browse

Question: I found that when the transaction has no commit or rollback, it will automatically rollback after the http request ends

Code example:

<code>$this->db->begin();

// 这时候user表这条记录就已经被锁住了。。。
$user = \Users::findFirst($id);
$user->name = '写锁啊!';
sleep(15);

$user->save();
return ;
</code>

But when this request ends, the record in the database can be edited again. . .
I want to ask whether it is nginx, fpm or phalcon that automatically calls PDO->rollback(); ??????

Reply content:

Question: I found that when the transaction has no commit or rollback, it will automatically rollback after the http request ends

Code example:

<code>$this->db->begin();

// 这时候user表这条记录就已经被锁住了。。。
$user = \Users::findFirst($id);
$user->name = '写锁啊!';
sleep(15);

$user->save();
return ;
</code>

But when this request ends, the record in the database can be edited again. . .
I want to ask whether it is nginx, fpm or phalcon that automatically calls PDO->rollback(); ??????

MySQL's AUTOCOMMIT automatic submission parameter is turned on by default. It will only be submitted when a commit command is encountered in the transaction.
If it is operated through a MySQL driver in other languages, the MySQL driver will automatically ROLLBACK has no processed transactions.

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