[英]PHP-MYSQL Cannot delete on mysqli_multi_query
I have two querys that have to delete rows on different tables when a checkbox is checked. 我有两个查询,当选中一个复选框时,它们必须删除不同表上的行。 The problem is that only executes one of the querys and ignores the other one. 问题在于仅执行查询之一,而忽略另一个查询。
Here's the code: 这是代码:
if(isset($_POST["che".$i.""])){
$query4 = "DELETE FROM gastos WHERE id_dedicaciondos = $idded AND id_usuario=$idu;";
$query4 .= "DELETE FROM dedicacio WHERE id_dedicacion = $idded AND id_usuario=$idu;" ;
if(mysqli_multi_query($connexio,$query4)){
do{
if ($result = mysqli_store_result($connexio)) {
mysqli_free_result($result);
}
}while(mysqli_next_result($connexio) && mysqli_more_results($connexio));
}
}
Only deletes the rows from the second query... If I change the order of the querys the result is exactly the same, only deletes from the query "delete from dedicacio". 仅从第二个查询中删除行...如果更改查询的顺序,结果完全相同,则仅从查询中删除“从dedicacio删除”。
What can I do? 我能做什么?
Thanks in advance 提前致谢
UPDATE 更新
I've tried the next: 我已经尝试了下一个:
if(isset($_POST["che".$i.""])){
$query4 = "DELETE FROM gastos WHERE id_dedicaciondos = ".$idded.";";
$query5 = "DELETE FROM dedicacio WHERE id_dedicacion = ".$idded.";";
if(mysqli_query($connexio,$query4)){
echo "YES!";
}
if(mysqli_query($connexio,$query5)){
echo "YES2!";
}
}
It shows "YES!" 它显示“是!” and "YES2!" 和“是2!” But the query don't delete anything on the "gastos" table :( 但是查询不会删除“ gastos”表上的任何内容:(
UPDATE 更新
I solved by myself adding a "ON DELETE CASCADE" to the id_dedicaciondos that references id_dedicacions. 我自己解决了在引用id_dedicacions的id_dedicaciondos中添加“ ON DELETE CASCADE”的问题。
TRy to use this code: 尝试使用此代码:
if ($mysqli->multi_query($query4)) {
do {
if ($result = $mysqli->store_result()) {
$result->free();
}
/* print divider */
if ($mysqli->more_results()) {
printf("-----------------\n");
}
} while ($mysqli->next_result());
}
Just tested this and it works fine: 刚刚测试过,它可以正常工作:
<?php
$mysqli = new mysqli("localhost", "user", "pass", "testdb");
$query4 = "DELETE FROM test_table1 WHERE num = 0;";
$query4 .= "DELETE FROM test_table2 WHERE num = 0;";
$mysqli->multi_query($query4);
while ($mysqli->next_result()) {;} // flush queries
$mysqli->close();
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.