gpt4 book ai didi

php - 使用 mysqli_multi_query() 删除表

转载 作者:行者123 更新时间:2023-11-29 06:48:04 24 4
gpt4 key购买 nike

我正在尝试删除我的主表“eleve”,同时删除主键在此的其他表。我尝试了所附代码,但出现错误:

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

}
}

最佳答案

不确定为什么你想这样做,有更好的方法,但要回答你的问题,请这样做:

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

并且还要记住清除结果,否则您将无法执行另一个查询,但我不认为删除会返回结果。

while(mysqli_next_result($con)){;} //clear any remaining query results.

还请记住,如果一个查询失败,其余所有查询都将不会运行。因此,要调试,请先尝试单独运行每个查询,并确保它一切正常,因为它的删除语句会在运行查询之前备份数据库,并在需要时恢复。

关于php - 使用 mysqli_multi_query() 删除表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48604399/

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