使用 mysqli_multi_query() 删除表格
Deleting tables with mysqli_multi_query()
我正在尝试删除我的原则 table 'eleve',同时删除其他原则 table,这些原则在此原则中具有主键。我在附加代码中尝试过,但出现错误:
(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);
并且还记得清除结果,否则您将无法执行另一个查询,但我认为删除不会 return 结果。
while(mysqli_next_result($con)){;} //clear any remaining query results.
还要记住,如果一个查询失败,其余的都不会 运行。因此要进行调试,请先尝试 运行 分别对每个查询进行调试,并确保一切正常,因为它的删除语句会在 运行 查询之前备份您的数据库,并在需要时进行恢复。
我正在尝试删除我的原则 table 'eleve',同时删除其他原则 table,这些原则在此原则中具有主键。我在附加代码中尝试过,但出现错误:
(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);
并且还记得清除结果,否则您将无法执行另一个查询,但我认为删除不会 return 结果。
while(mysqli_next_result($con)){;} //clear any remaining query results.
还要记住,如果一个查询失败,其余的都不会 运行。因此要进行调试,请先尝试 运行 分别对每个查询进行调试,并确保一切正常,因为它的删除语句会在 运行 查询之前备份您的数据库,并在需要时进行恢复。