The following articles mainly introduce the actual operation steps for connecting php to the MySQL database and the description of the application code for connecting php to the MySQL database. The following describes the relevant content, I hope it will help you in this regard.
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
PHP for MySQL
Open extension = php_MySQL.dll
- <?php
- $servername = "127.0.0.1";
- $username = "root";
- $password = "123456";
- $conn = MySQL_connect($servername, $username, $password);
Create a MySQL connection
- if($conn) {
Echo "MySQL database connected ";
- }
- //MySQL_select_db("easytoo");
Select the database to connect
Or
- MySQL_query("use easytoo",$conn);
Select to connect to the MySQL database
- MySQL_query("SET NAMES utf8");
- $rs = MySQL_query("select id from et_category");
Query and obtain a dataset
- MySQL_num_rows($rs);
Obtain the total number of record sets.
- while($row= mysql _fetch_array($rs))
Cyclic Dataset
- {
- echo "$row[0]<br>";
- }
- mysql_free_result($rs);
Release rs
- mysql_close($conn);
Close connection
- ?>
The above content is an introduction to the connection of php to the MySQL database. I hope you will have some gains.