Home >Backend Development >PHP Problem >How to delete database data in php

How to delete database data in php

王林
王林Original
2020-11-05 10:32:064136browse

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.

How to delete database data in php

#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:

How to delete database data in php

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=&#39;Griffin&#39;");
mysqli_close($con);
?>

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

How to delete database data in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn