PHP7.27: connect mysql 5.7 using new mysqli
<!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>
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)