php 连接数据库 Warning: mysqli_connect(): (HY000/2002): No such file or directory in
1.错误代码
//主机名 $db_host = 'localhost'; //用户名 $db_user = 'jaing'; //密码 $db_password = '1'; //数据库名 $db_name = 'rongShop'; //端口 $db_port = '3306'; //连接数据库 $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die('连接数据库失败!');
错误原因:未加端口参数;用户名填写错误
修改db_host,$db_user即可
//主机名 $db_host = 'localhost:3306'; //用户名 $db_user = 'jiang'; //密码 $db_password = '1'; //数据库名 $db_name = 'rongShop'; //端口 $db_port = '3306'; //连接数据库 $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die('连接数据库失败!');