我有一个项目文件,我的语法有问题,例如:
mysqli_query($connection,"START TRANSACTION");
$mysql_query = mysqli_multi_query($connection,"
INSERT INTO `TABLE 1` (`ID`, `VAL`) VALUES (NULL, 'NAMBAH 1');
INSERT INTO `TABLE 2` (`ID`, `VAL`) VALUES (NULL, 'NAMBAH 2');
INSERT INTO `TABLE 3` (`ID`, `VAL`) VALUES (NULL, 'NAMBAH 3');
");
if(!$mysql_query){
echo "Syntax MySQL: " . mysqli_error($connection);
}else{
do{
// Store first result set
if ($result=mysqli_store_result($connection)){
mysqli_free_result($result);
}
}while (mysqli_next_result($connection));
}
如果不可能,我想回滚如果一个MySQL Query无法插入,我想我们可以逐个检查这个查询,
感谢您提前!
答案 0 :(得分:0)
它应该是这样的:
mysqli_autocommit($connection, FALSE);
$mysql_query = mysqli_multi_query($connection,"
INSERT INTO `TABLE 1` (`ID`, `VAL`) VALUES (NULL, 'NAMBAH 1');
INSERT INTO `TABLE 2` (`ID`, `VAL`) VALUES (NULL, 'NAMBAH 2');
INSERT INTO `TABLE 3` (`ID`, `VAL`) VALUES (NULL, 'NAMBAH 3');
");
do{
// Store first result set
if ($result=mysqli_store_result($connection)){
mysqli_free_result($result);
}
}while (mysqli_next_result($connection));
if( $mysqli_errno($connection)){
$mysqli_commit($connection);
}else{
echo "MySQL Error: " . mysqli_error($connection);
$mysqli_rollback($connection);
}