PHP7.27: connect mysql 5.7
程序员文章站
2022-04-04 09:51:48
my sql '127.0.0.1:3306', 'db' => 'sakila', 'db_user' => 'root', 'db_pwd' => '888888', ); $mysqli = @new mysqli($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 /* 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>