使用mysqli_multi_query()删除表 [英] Deleting tables with mysqli_multi_query()
问题描述
我正在尝试删除我的主表"eleve",并删除其他表中具有其主键的其他表.我尝试像在所附的代码中一样,但是出现了错误:
I'm trying to delete my principle table 'eleve', with deleting others table which has their primary key in this one. I tried like in the attached code, but I got an error:
(从erce语法中删除,其中ID_BOURCE = 1从类中删除,而ID_CLASS = 1从p'-la ligne 1中删除)
(Erreur de syntaxe pr�s de 'from bource where ID_BOURCE = 1delete from class where ID_CLASS = 1delete from p' � la ligne 1)
有什么想法吗?
if (isset($_POST['butAj4'])) {
$queryDel = "delete from inscription where NUM_INSCRIPTION = $NUM_INSCRIPTION";
$queryDel. = "delete from bource where ID_BOURCE = $ID_BOURCE";
$queryDel. = "delete from class where ID_CLASS = $ID_CLASS";
$queryDel. = "delete from project where ID_PROJECT = $ID_PROJECT";
$queryDel. = "delete from annee_scolaire where ID_ANNEE = $ID_ANNEE";
$queryDel. = "delete from eleve where CIN_ELEVE = '$InputCIN'";
if (mysqli_multi_query($con, $queryDel)) {
$msg3 = "<div class='alert alert-success'>Bien suppression</div>";
} else {
$msg3 = "<div class='alert alert-danger'>error dans la suppression</div>".mysqli_error($con);
}
}
推荐答案
不确定为什么要这样做,有更好的方法来回答您的问题,就像这样:
Not sure why you want to do it like this there are better ways but to answer your question do it like this:
$queryDel = "
delete from inscription where NUM_INSCRIPTION= $NUM_INSCRIPTION ;
delete from bource where ID_BOURCE = $ID_BOURCE ;
delete from class where ID_CLASS = $ID_CLASS ;
delete from project where ID_PROJECT = $ID_PROJECT ;
delete from annee_scolaire where ID_ANNEE = $ID_ANNEE ;
delete from eleve where CIN_ELEVE = '$InputCIN'; ";
$result=mysqli_multi_query($con,$queryDel);
并且还记得清除结果,否则您将无法执行其他查询,但我不认为delete会返回结果.
and also remember to clear the results else you wont be able to perform another query but i don't think delete will return a result.
while(mysqli_next_result($con)){;} //clear any remaining query results.
还请记住,如果一个查询失败,其余所有查询将不会运行.因此,要进行调试,请尝试先分别运行每个查询,并确保它们都可以正常运行,因为它的一条delete语句会在运行查询之前备份数据库,并在需要时进行还原.
also remember that if one query fails all the rest will not run. so to debug try running each query separately first and make sure it all works since its a delete statement back up your database before running the query and restore as when needed.
这篇关于使用mysqli_multi_query()删除表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!