…Apache 已经支持 PHP,已配置好PHP 扩展支持 MySQL 数据库,下面为如何在PHP网页中显示本地MySQL数据库的内容: 本地数据库存在一个表:student @test(localhost) 在“C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs”路径下新建一个php文件,内容为:
<!DOCTYPE html>
<html>
<body>
<table style='text-align:left;' border='1'>
<tr><th>SNO</th><th>Name</th><th>Age</th><th>College</th></tr>
<?php
$con = mysql_connect("localhost","root","666");
if(!$con){
die(mysql_error());
}
mysql_select_db("test",$con);
$sql = mysql_query("select * from student");
mysql_query("set name utf8");
mysql_query("set college utf8");
$datarow = mysql_num_rows($sql);
for($i=0;$i<$datarow;$i++){
$sql_arr = mysql_fetch_assoc($sql);
$sno = $sql_arr['SNO'];
$name = $sql_arr['Name'];
$age = $sql_arr['Age'];
$college = $sql_arr['College'];
echo "<tr><td>$sno</td><td>$name</td><td>$age</td><td>$college</td></tr>";
}
mysql_close($con);
?>
</table>
</body>
</html>
然后在浏览器中输入:http://localhost:8080/sjk3.php 显示为:
|