PHP PDO Delete Data From a MySQL Table
The SQL DELETE statement is use to delete a record from a table. We want to remove one of our products from our 'products' table for reason that we are not more selling that product.
The product we want to delete has an id = 1(WHERE id = 1).
// sql to delete a record
$sql = "DELETE FROM products WHERE id=1";
// use exec() because no results are returned
echo "Record deleted successfully";
echo $sql . "<br>" . $e->getMessage();
If you forget to use the WHERE id=1, all records in your database will be deleted.