我的工作,其跟蹤的內容是該領域的系統之前備份列數據(到另一個表/列),更新在它之前。我更願意使用以前的數據表,但我可以選擇其他選項。這是一些示例代碼,這將完成該任務:PHP的mysqli - 更新列
<?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();
}
?>
爲什麼不增加一列叫'** previous_val **'? – Matt 2012-08-02 16:05:25
對我而言數據是否會被移動到新的表格或列中並不重要。任何一個都可以工作 – mlishn 2012-08-02 16:06:21
從數據使用的角度來看,添加一列,而不是使用** a)**主鍵,** b)**外鍵和** c)**像我說的值 – Matt 2012-08-02 16:09:41