gpt4 book ai didi

php - 在 mysqli_multi_query() 过程中检查 INSERT

转载 作者:行者123 更新时间:2023-11-30 23:44:44 26 4
gpt4 key购买 nike

我有一个项目文件,我的语法有问题,例如:

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插入失败,我想回滚,我想我们可以一个一个地检查这个查询,

感谢提前!

最佳答案

应该是这样的:

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);
}

关于php - 在 mysqli_multi_query() 过程中检查 INSERT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45031606/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com