$mysqli = new MySQLi("localhost","root","123456","liuyan");
if(!$mysqli){
die($mysqli->error);
}
function showTable($mysqli,$table_name){
$sql = "select * from $table_name";
$res = $mysqli->query($sql);
//获取返回总行数和列数
echo "共有:".$res->num_rows."行;共有:".$res->field_count."列。";
//获取表头---从$res取出
echo "
";
while($field=$res->fetch_field()){
echo "{$field->name} | ";
}
echo "
";
//循环取出数据
while($row=$res->fetch_row()){
echo "";
foreach($row as $value){
echo "$value | ";
}
echo "
";
}
echo "
";
$res->free();
}
showTable($mysqli,"news");
?>