我目前正在搞乱mysql。我无法使用此代码mysqli_query($conn, "DELETE FORM amount");
删除表“amount”中的所有行。使用该代码,我甚至无法访问我的页面。
$conn = new mysqli(localhost, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO freetexts (amount)
VALUES ('3')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$sql = "SELECT amount FROM freetexts";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "Amount: " . $row["amount"];
}
} else {
echo "0 results";
}
mysqli_query($conn, "DELETE FROM amount");
$conn->close();
答案 0 :(得分:0)
更改
mysqli_query($conn, "DELETE FORM amount");
向
mysqli_query($conn, "DELETE FROM amount");
(拼写错误FROM
)
我也认为你不想删除表amount
中的所有记录,而只是删除表freetexts
中找到的记录......所以这意味着你需要改变查询。为了给您提供有关此类内容的进一步建议,请使用表格布局更新您的问题。
答案 1 :(得分:-1)
BD可能有一个保护,拒绝删除没有条件子句的所有行的命令。
试试这个:TRUNCATE [table_name]
答案 2 :(得分:-1)
$column = freetexts;
您需要更改
mysqli_query($conn, "DELETE FROM amount");
到
mysqli_query($conn, "DELETE FROM `$column` WHERE 1");