1. Connect MySQL database with PHP
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) );
Then add data to the database:
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:
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:
id | nikename | ".$row[0]." | "; echo"".$row[1]." | "; echo"".$row[2]." | "; echo""; } ?>
---|
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
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)!