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
Previous article:PHP export mysql database to excel table_PHP tutorial
Next article:Installation and configuration of memcached.exe in windows/linux/php_PHP tutorial
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 Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|