(Advanced article) PHP connects to the database to achieve the most basic addition, deletion, modification, and query (process-oriented)

Source: Internet
Author: User
This article describes (advanced) how to connect PHP to the database to achieve the most basic addition, deletion, modification, and query (process-oriented) details. For more information, see section 1. connect PHP to the MySQL database.

 

2. add data to the database

First, I created a user table in the beyondweb_test database for demonstration.

SQL statement:

CREATE TABLE user(    id INT(20) PRIMARY KEY AUTO_INCREMENT,    nikename VARCHAR(30),    email VARCHAR(40));

Then add data to the database:

 

3. modify data in the database

We also perform operations based on the user table. for example, we change "zhang san" to "Li Si". The php code is as follows:

 

In fact, the SQL statement has changed, and the others are the same.

4. query databases

You only need to replace the SQL statement. for example, you can query all the data in the table and output it in the form of a table:

     
"; echo" "; echo" "; echo" "; echo" "; }?>
id nikename email
".$row[0]."".$row[1]."".$row[2]."

5. delete data

As we have already provided solutions for adding, modifying, and deleting data, "add, delete, modify, and query" will have one "delete" left, next, let's take a look at how data is deleted. In fact, it's similar to the above. just change an SQL statement in one sentence.

 

The above is (Advanced article) PHP connection to the database to achieve the most basic addition, deletion, modification, and query (process-oriented) content. For more information, please follow the PHP Chinese network (www.php1.cn )!

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.