我正在开发一个系统,该系统在更新之前跟踪该领域的内容。我更喜欢使用表格来存储以前的数据,但我对其他选项持开放态度。这是一些可以完成任务的示例代码:
<?php
$initial_value = $_POST['some_value'];
$id =231212213; // some id
$stmt = $mysqli->prepare("SELECT column FROM table WHERE user=?")
$stmt->bindParam("s", $id);
$stmt->execute();
$stmt->bind_result($column);
$stmt->fetch();
if ($column !="") {
//edit : it doesnt matter to me whether the data is moved into a new table or column
$stmtA = $mysqli->prepare("UPDATE another_table SET backup_column=? WHERE user=?");
$stmtA->bindParam("ss", $column, $id);
$stmtA->execute();
$stmtB = $mysqli->prepare("UPDATE table SET column=? WHERE user=?");
$stmtB->bindParam("ss", $initial_value, $id);
$stmtB->execute();
}
?>