我想截断多个表。下面是代码:
$del_all = $conn->prepare("TRUNCATE TABLE students"); //line 214
$res = $del_all->execute();
$del_all->store_result();
$del_all->close();
$del_all_fees = $conn->prepare("TRUNCATE TABLE fees");
$res_fees = $del_all_fees->execute();
$del_all_fees->store_result();
$del_all_fees->close();
$del_all_test = $conn->prepare("TRUNCATE TABLE test");
$res_test = $del_all_test->execute();
$del_all_test->store_result();
$del_all_test->close();
$del_all_jan = $conn->prepare("TRUNCATE TABLE jan");
$res_jan = $del_all_jan->execute();
$del_all_jan->store_result();
$del_all_jan->close();
$del_all_feb = $conn->prepare("TRUNCATE TABLE feb");
$res_feb = $del_all_feb->execute();
$del_all_feb->store_result();
$del_all_feb->close();
$del_all_mar = $conn->prepare("TRUNCATE TABLE mar");
$res_mar = $del_all_mar->execute();
$del_all_mar->store_result();
$del_all_mar->close();
if($res>0 && $res_fees>0 && $res_test>0 && $res_jan>0 && $res_feb>0 && $res_mar>0){
echo "<div class='w3-panel w3-green w3-display-container' style='width:40%;'>
<span onclick='this.parentElement.style.display='none''
class='w3-button w3-large w3-display-topright'>×</span>
<p>All Records deleted successfully</p>
</div>";
} else{
echo "<div class='w3-panel w3-green w3-display-container' style='width:40%;'>
<span onclick='this.parentElement.style.display='none''
class='w3-button w3-large w3-display-topright'>×</span>
<p>Something went wrong. Records not deleted</p>
</div>";
}
有一个错误'Commands out of sync; you can't run this command now' in C:\wamp\www\classlearn\delete.php on line 214
。我知道无法同时执行查询,这就是为什么我将close()
函数放在两个查询之间,并将store_result()
放在每个查询之后的原因。但随后,它也给出了相同的错误。可能是什么问题?请帮忙。
我尝试使用以下不同方式进行编码:
$del_all = "TRUNCATE TABLE students";
$del_all_fees = "TRUNCATE TABLE fees";
$del_all_test = "TRUNCATE TABLE test";
$del_all_jan = "TRUNCATE TABLE jan";
$del_all_feb = "TRUNCATE TABLE feb";
$del_all_mar = "TRUNCATE TABLE mar";
if($conn->query($del_all)&&$conn->query($del_all_fees)&&$conn->query($del_all_test)&&$conn->query($del_all_jan)&&$conn->query($del_all_feb)&&$conn->query($del_all_mar){
echo "<p>All Records deleted successfully</p>"
} else
echo "Failed to delete records";
然后它也没有用。