<?php
function showTable($tabname){
$mysqli=new mysqli("localhost","root","123456","worddb");
if($mysqli->connect_error){
die("连接失败".$mysqli->connect_error);
}
$sql="select * from $tabname";
$res=$mysqli->query($sql);
//获取总行数和列数
echo "行数: ".$res->num_rows."列数:".$res->field_count;
echo "<br/>";
echo "<table border='1'><tr>";
//取出表头信息
while ($field=$res->fetch_field()){
echo "<th>$field->name</th>";
}
echo"</tr>";
//循环取出数据
while ($row=$res->fetch_row()){
echo "<tr>";
foreach ($row as $key=>$val){
echo "<td>$val</td>";
}
echo "</tr>";
}
echo "</table>";
//关闭资源
$res->free();
$mysqli->close();
}
showTable("words");
?>