据我了解,事务开始于调用$mysqli->autocommit(FALSE);语句,然后终止于调用$mysqli->commit();命令,如下例所示。
<?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
?>
我理解正确吗?如果不能,请指正我,因为这实际上是我第一次在现实生活中使用交易。
谢谢。
互换的青春
慕标5832272