DELETE statement is used to delete rows from a database table.
Syntax
DELETE FROM table_name
WHERE some_column = some_value
Note: Please pay attention to the WHERE clause in the DELETE syntax. The WHERE clause specifies which records need to be deleted. If you want to omit the WHERE clause, all records will be deleted!
To learn more about SQL, please visit our SQL tutorial.
Example description
Let’s take a look at the data in our Myguests first:
Let’s delete the firstname=’Mary’ data
<?php header("Content-type:text/html;charset=utf-8"); //设置编码 $con=mysqli_connect("localhost","root","root","test"); // 检测连接 if (mysqli_connect_errno()) { echo "连接失败: " . mysqli_connect_error(); } mysqli_query($con,"DELETE FROM Myguests WHERE firstname='Mary'"); mysqli_close($con); ?>
Run the program:
Let’s look at the data in the table again
Has been deleted successfully
【Remember】
1. Be sure to remember to add the where condition when deleting, otherwise the entire table will be cleared record of.
2. Be sure to back up, back up, back up before deleting important data.