php mysql 事务无法回滚 rollback不起作用
<?phpheader("Content-type:text/html;charset=utf-8");$mysqli=newMySQLi("localhost","ro...
<?php
header ( "Content-type: text/html;charset=utf-8" );
$mysqli = new MySQLi ( "localhost", "root", "123456", "test" );
if ($mysqli->connect_error) {
die ( "error!!".$mysqli->connect_error );
}
$mysqli->autocommit ( false );
$sql_1 = "update account set balance=balance-2 where id=1";
$sql_2 = "update accountx set balance=balance+2 where id=2";
$Q1 = $mysqli->query ( $sql_1 );
$Q2 = $mysqli->query ( $sql_2 );
if (!$Q2 || !$Q1) {
echo $mysqli->error;
$mysqli->rollback ();
} else {
$mysqli->commit ();
}
$mysqli->close ();
?> 展开
header ( "Content-type: text/html;charset=utf-8" );
$mysqli = new MySQLi ( "localhost", "root", "123456", "test" );
if ($mysqli->connect_error) {
die ( "error!!".$mysqli->connect_error );
}
$mysqli->autocommit ( false );
$sql_1 = "update account set balance=balance-2 where id=1";
$sql_2 = "update accountx set balance=balance+2 where id=2";
$Q1 = $mysqli->query ( $sql_1 );
$Q2 = $mysqli->query ( $sql_2 );
if (!$Q2 || !$Q1) {
echo $mysqli->error;
$mysqli->rollback ();
} else {
$mysqli->commit ();
}
$mysqli->close ();
?> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询