PHP reads MySQL data code. Create a view. php file with the following code :? Php $ linkmysql_connect (localhost, root, previous administrator password); if (! $ Link) echo no connection successful !; Elsee creates a view. php file with the following content:
The code is as follows:
$ Link = mysql_connect ("localhost", "root", "previous administrator password ");
If (! $ Link) echo "no connection successful! ";
Else echo "connection successful! ";
?>
In this way, we connect to the MySQL database. Next, we will read some of the code for reading data. based on the introduction of the MySQL data source table structure, we will try to read:
Depart varchar (45) department name
Ename varchar (45) employee name
Pcname varchar (45) PC name
The three data segments.
In view. php, write the code next to the front:
The code is as follows:
Mysql_select_db ("infosystem", $ link); // select a database
$ Q = "SELECT * FROM info"; // SQL query statement
Mysql_query ("set names GB2312 ");
$ Rs = mysql_query ($ q, $ link); // Obtain a dataset
If (! $ Rs) {die ("Valid result! ");}
Echo"
";Echo"
Department name |
Employee Name |
PC name |
";While ($ row = mysql_fetch_row ($ rs) echo"
$ Row [1] |
$ Row [2] |
$ Row [3] |
"; // Display DataEcho"
";
Mysql_free_result ($ rs); // Close the dataset
?>
"Infosystem" indicates the database name and "info" indicates the table name. You can modify the settings as needed.
Next, run it ~ How about ~ Is the data successfully read?
The pipeline code is as follows :? Php $ link = mysql_connect ("localhost", "root", "previous administrator password"); if (! $ Link) echo "no connection successful! "; Elsee...