PHP7.27: connect mysql 5.7

Posted ®Geovin Du Dream Park™

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP7.27: connect mysql 5.7相关的知识,希望对你有一定的参考价值。

<!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:
" . $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:
" .  $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:
" . $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>

  

以上是关于PHP7.27: connect mysql 5.7的主要内容,如果未能解决你的问题,请参考以下文章

php7.27: export excel from mysql

2003 - Can‘t connect to MySQL server on ‘10.211.55.5‘ (61 “Connection refused“)

PHP7.27: pdf

MySQL驱动阅读------Connection连接的建立,基于JDBC-----5.1.26

2003 - Can‘t connect to MySQL server on ‘10.211.55.5‘ (61 “Connection refused“)

PHP7.1-soap扩展安装