我正在使用PHP将数据从表插入具有附加列的另一个,然后从第一个表中删除该行。但是,我似乎无法使它起作用:
public function insertReq($dID, $bphone)
{
$stmt = $this->conn->prepare("INSERT INTO RequestedDevices(dID, deviceName, Medical, Description, Educational, DevicePicture, bphone) VALUES((SELECT id, deviceName, Medical, Description, Educational, DevicePicture WHERE id = ?), ?)");
$stmt->bind_param("ss", $dID, $bphone);
$flag = $stmt->execute();
$stmt1 = $this->conn->prepare("DELETE FROM DEVICE WHERE id= ? ");
$stmt1->bind_param("s", $dID);
$flag1 = $stmt1->execute();
if ($flag & flag1) {
return ADDED;
} else {
return NOT_ADDED;
}
}
您需要在选择中将附加列作为常数包含,并且您不需要围绕选择的值((。:
public function insertReq($dID, $bphone)
{
$stmt = $this->conn->prepare("INSERT INTO RequestedDevices(dID, deviceName, Medical, Description, Educational, DevicePicture, bphone) SELECT id, deviceName, Medical, Description, Educational, DevicePicture, ? WHERE id = ? from TABLE NAME )");
$flag = $stmt->execute(["someAdditionalColumData", "someID"]);
$stmt1 = $this->conn->prepare("DELETE FROM DEVICE WHERE id= ? ");
$flag1 = $stmt1->execute(["originalTableID"]);
if ($flag & flag1) {
return ADDED;
} else {
return NOT_ADDED;
}
}