Easy Tutorial
❮ Func Array List Func Curl_Share_Setopt ❯

PHP MySQL Delete


The DELETE statement is used to remove rows from a database table.


Deleting Data from a Database

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

Syntax

DELETE FROM table_name
WHERE some_column = some_value

Note: Be aware of the WHERE clause in the DELETE syntax. The WHERE clause specifies which records should be deleted. If you omit the WHERE clause, all records will be deleted!

To learn more about SQL, visit our SQL Tutorial.

To execute the above statement in PHP, we must use the mysqli_query() function. This function is used to send a query or command to a MySQL connection.

Example

Consider the following "Persons" table:

FirstName LastName Age
Peter Griffin 35
Glenn Quagmire 33

The following example deletes all records from the "Persons" table where LastName='Griffin':

<?php
$con=mysqli_connect("localhost","username","password","database");
// Check connection
if (mysqli_connect_errno())
{
    echo "Failed to connect: " . mysqli_connect_error();
}

mysqli_query($con,"DELETE FROM Persons WHERE LastName='Griffin'");

mysqli_close($con);
?>

After this deletion, the "Persons" table will look like this:

FirstName LastName Age
Glenn Quagmire 33
❮ Func Array List Func Curl_Share_Setopt ❯