2 つの異なるレコードを 2 つの異なるテーブルに挿入し、元のレコードを削除したいと考えています。このような
$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
クエリが完了するまで 4 回ではなく 1 回実行します。