我有这行代码:
$mysqli = new mysqli("localhost", "user", "pass", "db");
我将 XAMPP 用于 Apache 和 MySQL。如果我使用上面的行,则会引发以下错误:
Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'user'@'localhost' (using password: YES) in C:\xampp\htdocs\xo\php\connect.php on line 2
Failed to connect to MySQL: (1045) Access denied for user 'user'@'localhost' (using password: YES)
Warning: main(): Couldn't fetch mysqli in C:\xampp\htdocs\xo\php\connect.php on line 6
如果我用 127.0.0.1(我试过)替换 localhost 也是一样的。但是,如果我使用我的内部网络 IP(在本例中为 192.168.1.101)而不是 localhost,它会成功连接。