欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP7.27: connect mysql 5.7 using new mysqli_connect

程序员文章站 2022-10-04 16:19:23
my sql '127.0.0.1:3306', 'db' => 'sakila', 'db_user' => 'root', 'db_pwd' => '888888', ); $link = mysqli_connect($mysql_conf['host'],$mysql_conf['db_us... ......
<!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'  => '888888', 
    );	
$link = mysqli_connect($mysql_conf['host'],$mysql_conf['db_user'], $mysql_conf['db_pwd'],$mysql_conf['db']);

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "select * from city ORDER BY city_id LIMIT 5;";
// 获取表格字段属性
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>