我想将两条不同的记录插入两个不同的表中并删除原始的一个。像这样
$msgid = POST_['roll_id'];
$query = "INSERT INTO del_subscription SELECT * from subscription WHERE mem_id='$msgid'";
$query1 = "INSERT INTO del_user_data SELECT * from user_data WHERE mem1_id='$msgid'";
$query2 ="DELETE FROM subscription WHERE mem_id='$msgid'";
$query3 ="DELETE FROM user_data WHERE mem_id='$msgid'";
可以对这个查询使用 multi_query。
我使用了多查询,但第一个查询只能工作
$msgid = POST_['roll_id'];
if (strlen($msgid) > 0)
{
$query = "INSERT INTO del_subscription SELECT * FROM subscription WHERE name='$msgid' AND renewal='yes';" ;
$query .= "INSERT INTO del_user_data SELECT * FROM user_data WHERE name='$msgid'AND wait='no';";
$query .= "DELETE FROM subscription WHERE name='$msgid' AND renewal='yes';" ;
$query .= "DELETE FROM user_data WHERE name='$msgid' AND wait='no'";
if (mysqli_multi_query($con, $query))
{
do {
/* store first result set */
if ($result = mysqli_store_result($con)) {
while ($row = mysqli_fetch_row($result)) {
echo "null";
}
if($result) { mysqli_free_result($result); }
}
/* print divider */
if (mysqli_more_results($con)) {
echo "<html><head><script>alert('Member Deleted');</script></head></html>";
echo "<meta http-equiv='refresh' content='0; url=view_mem.php'>";
}
} while (mysqli_next_result($con));
}
}
else {
echo "<html><head><script>alert('ERROR! Delete Operation Unsuccessful');</script></head></html>";
echo "<meta http-equiv='refresh' content='0; url=view_mem.php'>";
}
/* close connection */
mysqli_close($con);
在这里,我们希望运行Member Deleted
一次而不是四次,直到完成查询。