我将在每个午夜运行cron作业(php脚本),以将所有记录从一个表复制到另一个表,然后从第一个表中删除它们。
这是我现在拥有的:
<?php
include('conf/conn.php');
$result = mysqli_query($conn, "SHOW TABLES FROM mydb LIKE '%salon%'");
while($table = mysqli_fetch_array($result)) {
$tableToCopy = $table[0];
mysqli_begin_transaction($conn, MYSQLI_TRANS_START_READ_ONLY);
mysqli_query($conn, "INSERT INTO history SELECT * FROM $tableToCopy");
// Here is where I'm stuck
// $sql = "INSERT INTO history SELECT * FROM $tableToCopy; ";
// $sql.= "DELETE FROM $tableToCopy; ";
// if (!$mysqli->multi_query($sql)) {
// echo "Both executions failed: (" . $mysqli->errno . ") " . $mysqli->error;
// }
mysqli_commit($conn);
mysqli_close($conn);
if (!mysqli_commit($conn)) {
echo 'Failed.';
echo '<br>';
} else {
echo 'Successful';
echo '<br>';
}
}
?>
我找不到如何在一个事务中进行多个查询。有人可以指导我吗?预先感谢。