Create a view. php file with the following content:
CopyCode The Code is as follows: <? PHP
$ 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:
Copy code The Code is as follows: <? PHP
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 "<Table> ";
Echo "<tr> <TD> Department name </TD> <TD> employee name </TD> <TD> PC name </TD> </tr> ";
While ($ ROW = mysql_fetch_row ($ RS )) echo "<tr> <TD> $ row [1] </TD> <TD> $ row [2] </TD> <TD> $ row [3] </TD> </tr> "; // display data
Echo "</table> ";
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?