Create a new view.php file with the following contents:
Copy the Code code as follows:
$link =mysql_connect ("localhost", "root", "previous Administrator password");
if (! $link) echo "Not connected successfully!";
else echo "connected successfully!";
?>
In this way, we connected to the MySQL database, and then the data read part of the code, according to my MySQL data source table structure of the introduction, we are experimental to read:
Depart varchar (45) Department name
ename varchar (45) Employee name
Pcname varchar PC Name
These three pieces of data.
In the view.php, immediately preceding code continues to write:
Copy the Code code as follows:
mysql_select_db ("Infosystem", $link); Select Database
$q = "SELECT * from Info"; SQL query Statements
mysql_query ("SET NAMES GB2312");
$rs = mysql_query ($q, $link); Get Data Set
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] |
"; Show Data echo "
";
Mysql_free_result ($RS); To close a data set
?>
where "Infosystem" is the database name, "Info" is the name of the table. You can modify it according to your own circumstances as appropriate.
Next, run it ~ how ~ is the data being read smoothly?
The above describes the merry lonely Christmas php read the MySQL data code, including Merry Lonely Christmas content, I hope the PHP tutorial interested in a friend helpful.