Home >Backend Development >PHP Tutorial >PHP save data to Mysql database code example_PHP tutorial
The two most commonly used methods of saving data to the mysql database in php are the insert and update methods. Let me introduce the mysql data saving method to beginners.
There are three steps for PHP to write data to the MySQL database:
1. Establish a connection between PHP and MySQL
2. Open the MySQL database
3. Accept the page data and enter it into the specified table with PHP
You can directly use a database link file in steps 1 and 2: conn.php
The code is as follows
|
Copy code
|
||||||||||||
mysql_connect("localhost","root","");//Connect MySQL mysql_select_db("mythroad");//Select database
Of course, the premise is that the WEB server, PHP and MySQL have been installed, and the MySQL table "mythroad" has been created The three parameters in mysql_connect() are MySQL address, MySQL username and MySQL password Then the data is passed through the WEB page, and PHP writes the data into the table specified in the MySQL database through SQL statements, such as creating a new filepost.php
$uname = $_GET['n'];//GET method passes URL parameters Statement: 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 Previous article:PHP export mysql database to excel table_PHP tutorialNext article:PHP export mysql database to excel table_PHP tutorial Related articlesSee more |