PHP7.27: connect mysql 5.7

2018-07-16 02:48:47来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

<!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
/*
character_set_client	utf8
character_set_connection	utf8
character_set_database	utf8  -- 安装mysql时要设置的,所要考虑的
character_set_filesystem	binary
character_set_results	utf8
character_set_server	utf8
character_set_system	utf8
*/
$mysql_conf = array(
    'host'    => '127.0.0.1:3306', 
    'db'      => 'sakila', 
    'db_user' => 'root', 
    'db_pwd'  => '888888', 
    );

$mysqli = @new mysqli($mysql_conf['host'], $mysql_conf['db_user'], $mysql_conf['db_pwd']);
if ($mysqli->connect_errno) {
    die("could not connect to the database:\n" . $mysqli->connect_error);//诊断连接错误
}
$mysqli->query("set names 'utf8';");//编码转化
$select_db = $mysqli->select_db($mysql_conf['db']);
if (!$select_db) {
    die("could not connect to the db:\n" .  $mysqli->error);
}
$sql = "select city from city where city_id = 601;";
$res = $mysqli->query($sql);
	
//$result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());
//$password = mysql_result($result, 0);
//	echo $password;	
if (!$res) {
    die("sql error:\n" . $mysqli->error);
}
 while ($row = $res->fetch_assoc()) {
        var_dump($row);
    }
	
// 显示字段名称
$sql = "select * from city where city_id = 601;";	
$res = $mysqli->query($sql);	
while($field=$res->fetch_field())	
	echo("<br/>".$field->name);
	
//显示某行
$sql = "select * from city where city_id = 601;";	
$res = $mysqli->query($sql);	
while($rowd=$res->fetch_row())
	for($i=0;$i<$res->field_count;$i++)
		echo("<br/>".$rowd[$i]);
	
$res->free();
$mysqli->close();

?>
	
</body>
</html>

  

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:PHP防止数字太大转化为科学计数法的方法

下一篇:composer安装教程 windows系统 | Linux系统 | mac系统