-6ren">
gpt4 book ai didi

php - mysqli connect() 使用 IP 地址时收到错误消息

转载 作者:行者123 更新时间:2023-11-29 13:21:49 24 4
gpt4 key购买 nike

我直接从 php.net 上下载了这个

$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";

$mysqli = new mysqli("127.0.0.1", "user", "password", "database", 3306);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

echo $mysqli->host_info . "\n";

我的输出是这样的:

通过 UNIX 套接字的本地主机

我的问题是...为什么当我尝试使用第二种方法时会收到错误消息。

Failed to connect to MySQL: (1045) Access denied for user '*'@'127.0.0.1' (using password: YES)

最佳答案

确保配置文件中注释掉了跳过网络。另请查看您的用户表,看看是否允许“用户”从 127.0.0.1 连接

关于php - mysqli connect() 使用 IP 地址时收到错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20721075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com