<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">	
<meta charset="utf-8">
<title>my sql</title>
<meta name="keywords" content="geovindu">
<meta name="description" content="涂聚文"> 
</head>

<body>
<?php
// php 7.27 mysql 5.7 geovindu 涂聚文	
$mysql_conf = array(
    'host'    => '127.0.0.1:3306', 
    'db'      => 'sakila', 
    'db_user' => 'root', 
    'db_pwd'  => '8888888', 
    );	
$link = mysqli_connect($mysql_conf['host'],$mysql_conf['db_user'], $mysql_conf['db_pwd'],$mysql_conf['db']);
$link->query("set names 'utf8';");//编码转化
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "select * from city ORDER BY city_id;";
// 获取表格字段属性
if ($result = mysqli_query($link, $query)) {

    /* Get field information for all fields */
    while ($finfo = mysqli_fetch_field($result)) {

        printf("Name:     %s\n", $finfo->name);
        printf("Table:    %s\n", $finfo->table);
        printf("max. Len: %d\n", $finfo->max_length);
        printf("Flags:    %d\n", $finfo->flags);
        printf("Type:     %d\n\n", $finfo->type);
		echo("<br/>");
    }
    mysqli_free_result($result);
}
// 	
echo("<table border='1' align='center'><tr align='center'>");
// 显示字段名
if ($result = mysqli_query($link, $query))
{	
	while($field=mysqli_fetch_field($result))
	{
		echo("<td>".$field->name."</td>");
	}
	 mysqli_free_result($result);
}
echo("</tr>");	
	
// 显示行数据	
if ($resultrow = mysqli_query($link, $query))
{		
	while($row=mysqli_fetch_row($resultrow))
	{
	
		echo("<tr>");
		for($i=0;$i<mysqli_field_count($link);$i++)
		{
			echo("<td>".$row[$i]."</td>");
		}
		echo("</tr>");
	}
	
}
echo("</table>");		
/* close connection */
mysqli_close($link);
?>
</body>
</html>