<?php
try{
$dbh=new PDO('mysql:dnname=student_management;host=localhost','root','0623');
}catch(PDOException $e){
echo '数据库连接失败!'.$e->getMessage();
exit;
}
echo '<caption><h3>尊敬的用户您好:</h3></caption>';
echo '<table border="1" align="center" width=90%>';
echo '<caption><h1>学生信息表</h1></caption>';
echo '<tr bgcolor="#cccccc">';
echo '<th>序号</th><th>学号</th><th>班级</th><th>姓名</th><th>性别</th><th>成绩</th></tr>';
$stmt=$dbh->prepare("SELECT id,snr,class,sname,sex,score FROM student_info");
$stmt->execute();
$allRows=$stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($allRows as $row){
echo '<tr>';
echo '<td>'.$row['id'].'</td>';
echo '<td>'.$row['snr'].'</td>';
echo '<td>'.$row['class'].'</td>';
echo '<td>'.$row['sname'].'</td>';
echo '<td>'.$row['sex'].'</td>';
echo '<td>'.$row['score'].'</td>';
echo '</tr>';
}
echo '</table>';
?>