PHP MySQL Delete statement is particularly important in PHP, so this article will explain its related knowledge in detail.
Delete data in the database
The DELETE FROM statement is used to delete records from the 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 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 the MySQL connection.
Example
Please look at the "Persons" table below:
LastName Age
#Peter Griffin 35
Glenn Quagmire 33
The following example deletes all LastName='Griffin' in the "Persons" table Records:
<?php $con=mysqli_connect("localhost","username","password","database");// 检测连接if (mysqli_connect_errno()){ echo "连接失败: " . 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
Age##Glenn Quagmire 33
This article explains in detail the usage of the PHP MySQL Delete statement. For more learning materials, please pay attention to php Chinese You can watch it online.
Related content about PHP MySQL Update statement
Related content about PHP MySQL Order By keyword Knowledge
The above is the detailed content of Knowledge about PHP MySQL Delete statement. For more information, please follow other related articles on the PHP Chinese website!