PHP MySQL DELETE statement related knowledge

Source: Internet
Author: User
Tags sql tutorial mysql delete php mysql
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.