How to delete database data in php

王林
Release: 2023-03-07 10:32:02
Original
4034 people have browsed it

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
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!