To delete data from a table in MySQL, you use the DELETE
statement followed by the FROM
clause, specifying the table name. You can also add a WHERE
clause to specify which records should be deleted. Without a WHERE
clause, all records in the table will be deleted.
Here is an example of how to use the DELETE
statement:
<?php
// Creating a connection to the MySQL database
$conn = new mysqli("hostname", "username", "password", "database");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// SQL query to delete a record
$sql = "DELETE FROM tablename WHERE condition";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
$conn->close();
?>
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?