PHP MySQL DELETE statement is particularly important in PHP, so this article will explain its related knowledge in detail.
Delete data from a database
The delete from statement is used to delete records from a database table.
Grammar
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 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.
In order for PHP to execute the above statement, we must use the Mysqli_query () function. This function is used to send a query or command to a MySQL connection.
Instance
Take a look at the "Persons" table below:
FirstName LastName Age
Peter Griffin 35
Glenn Quagmire 33
The following instance deletes all Lastname= ' Griffin ' records in the "Persons" table:
<?php$con=mysqli_connect ("localhost", "username", "password", "database");//Detect connection if (Mysqli_connect_errno ()) { echo "Connection failed:". Mysqli_connect_error ();} Mysqli_query ($con, "DELETE from Persons WHERE lastname= ' Griffin '"); Mysqli_close ($con);? >
After this deletion, the "Persons" table looks like this:
FirstName LastName Age
Glenn Quagmire 33
This article explains in detail the use of PHP MySQL DELETE statement, more learning materials to pay attention to the PHP Chinese network can be viewed.