PHP7.27: connect mysql 5.7
程序员文章站
2022-06-30 12:55:55
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>
上一篇: 新兵跳伞
下一篇: CES 2018已发布新品大荟萃
推荐阅读
-
MySQL5.7 大大降低了半同步复制-数据丢失的风险
-
Install MySQL MariaDB version 10.0.10 with CONNECT and OQGRA_MySQL
-
Linux登录MySQL时出现 Can't connect to local MySQL server through socket '/tmp/mysql.sock'解决方法
-
Docker——Docker安装mysql5.7
-
PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法,deprecated
-
mysqli_connect跟mysql_connect的区别
-
MySQL错误ERROR 2002 (HY000): Can't connect to local MySQL se
-
MySQL5.7安装教程(压缩版)
-
php运行提示Can't connect to MySQL server on 'localhost'的_MySQL
-
MYSQL不能从远程连接的一个解决方法(s not allowed to connect t