Home >Backend Development >PHP Problem >How to delete database data in php
How to delete database data in php: Database data can be deleted by using the mysqli_query function combined with the [DELETE FROM table_name WHERE some_column = some_value] statement.
#DELETE FROM statement is used to delete records from a database table.
(Related learning video recommendations: java video tutorial)
Grammar:
DELETE FROM table_name WHERE some_column = some_value
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:
There is a "Persons" table below:
The following example deletes all LastName=' in the "Persons" table Griffin's record:
<?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:
Recommended tutorial: php training
The above is the detailed content of How to delete database data in php. For more information, please follow other related articles on the PHP Chinese website!