我写了一个代码来关闭 AutoCommit :
<?php
$con = mysqli_connect("localhost","root","","databases");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(mysqli_query($con,"SET autocommit=0")){//tried using mysqli_autocommit($con,FALSE);
// Insert some values
$a=mysqli_query($con,"INSERT INTO member VALUES (2,'Peter','Peter')");
$b=mysqli_query($con,"INSERT INTO member VALUES (3,honey,'honey')");
echo "a:";
echo $a;
echo "b:";
echo $b;
if($a&&$b){
mysqli_query($con,"COMMIT");//tried using mysqli_commit($con);
echo "in if";
}
else{
mysqli_query($con,"ROLLBACK");//tried using mysqli_rollback($con);
echo "in else";
}
}
mysqli_close($con);
?>
此代码的输出是:a:1 b: in else
但在表中,第一行被插入。我为此使用了 wamp。请让我知道我哪里出错了