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:
id |
nikename |
email |
"; echo"
".$row[0]." | "; echo"
".$row[1]." | "; echo"
".$row[2]." | "; echo"
"; }?>
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 )!