Create a new view.php file with the following content:
Copy the code 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 are connected to the MySQL database. Next, is the data reading part Code, according to the introduction of my MySQL data source table structure, we experimentally read:
Department varchar(45) Department name
ename varchar(45) Employee name
pcname varchar(45) PC name
These three paragraphs data.
Continue writing the previous code in view.php:
Copy the code The code is as follows:
mysql_select_db("infosystem", $link); //Select database
$q = "SELECT * FROM info"; //SQL query statement
mysql_query("SET NAMES GB2312");
$rs = mysql_query($q, $link); //Get the data set
if(!$rs){die ("Valid result!");}
echo "
";
echo "Department Name | Employee Name | |
";
while($row = mysql_fetch_row($rs)) echo "$row[1] | | $row[3] |
"; //Display data
echo "
";
mysql_free_result($ rs); //Close the data set
?> You can modify it as appropriate according to your own situation.
Next, run it~how~is the data read successfully?
The above introduces the merry lonely christmas PHP code for reading MySQL data, including the content of merry lonely christmas. I hope it will be helpful to friends who are interested in PHP tutorials.