PHP中的delete語句用于從數據庫中刪除記錄。其基本語法如下:
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// 創建連接
$conn = new mysqli($servername, $username, $password, $dbname);
// 檢查連接
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// 刪除記錄
$sql = "DELETE FROM tablename WHERE condition";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
// 關閉連接
$conn->close();
在上面的代碼中,DELETE FROM tablename WHERE condition
是刪除記錄的SQL語句。你需要將tablename
替換為要刪除記錄的表名,將condition
替換為符合要刪除記錄條件的條件語句。如果刪除記錄成功,將會輸出Record deleted successfully
,否則會輸出錯誤信息。最后,記得關閉數據庫連接。