Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP MySQL Delete

PHP MySQL Delete


DELETE statement is used to delete rows from a database table.


Delete Data from the Database

DELETE FROM statement is used to delete records from a database table.

Syntax



DELETE FROM table_name

WHERE some_column = some_value

**Note:** Please note the WHERE clause in the DELETE syntax. The WHERE clause specifies which records need to be deleted. If you omit the WHERE clause, all records will be deleted!

To learn more about SQL, please visit our SQL tutorial.

To make PHP execute the statement above, we must use the mysqli_query() function. This function is used to send queries or commands to the MySQL connection.

Example

Look at the "Persons" table below:

FirstName LastName Age
Peter Griffin 35
Glenn Quagmire 33

The example below deletes all records in the "Persons" table where LastName='Griffin':





After this deletion, the "Persons" table looks like this:

FirstName LastName Age
Glenn Quagmire 33