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

黄舟
Release: 2023-03-05 14:12:02
Original
1198 people have browsed it

1. Connect MySQL database with PHP

Copy after login

2. Add data to the database

First of all, I created such 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) );
Copy after login

Then add data to the database:

Copy after login

3. Modify the data in the database

We also operate based on the user table, for example "Zhang San" is changed to "Li Si", the php code is as follows:

Copy after login

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

4. Query the database

Just change the SQL statement. For example, query all the data in the table and output it in table form:

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

5. Delete data

The solutions to adding data, modifying data, and deleting data have been given before, so the only "delete" left in "add, delete, modify, and check" is. Let's take a look at how to delete data. In fact, it is the same as the above. It’s almost like a sentence, just change the SQL statement

Copy after login

The above is (advanced part) PHP connects to the database to implement the most basic addition, deletion, modification and query (process-oriented), and more related content Please pay attention to the PHP Chinese website (m.sbmmt.com)!


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
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!