如何在mysqli中开始和结束事务? [英] How to start and end transaction in mysqli?
本文介绍了如何在mysqli中开始和结束事务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
据我所知,事务如下所示,一旦调用$mysqli->autocommit(FALSE);
语句即开始,并在调用$mysqli->commit();
命令后终止.
As far as I understood transaction starts once we call $mysqli->autocommit(FALSE);
statement and ends after calling $mysqli->commit();
command like in the example below.
<?php
//Start transaction
$mysqli->autocommit(FALSE);
$mysqli->query('UPDATE `table` SET `col`=2');
$mysqli->query('UPDATE `table1` SET `col1`=3;');
$mysqli->commit();
//End transaction
//Executing other queries without transaction control
$mysqli->query("Select * from table1");
$mysqli->query("Update table1 set col1=2");
//End of executing other queries without transaction control
//Start transaction
$mysqli->autocommit(FALSE);
$mysqli->query('UPDATE `table` SET `col`=2');
$mysqli->query('UPDATE `table1` SET `col1`=3;');
$mysqli->commit();
//End transaction
?>
我理解正确吗?如果不能,请指正我,因为这实际上是我第一次在现实生活中使用交易.
Have I understood correctly? If not could you please correct me, because it is actually my first time using transactions in real life.
谢谢.
推荐答案
查看全文