MySqli cannot connect to localhost

I have this line of code:

$mysqli = new mysqli("localhost", "user", "pass", "db"); 

I use XAMPP for Apache and MySQL. If I use the line above, it causes the following error:

 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 

Same thing if I replace localhost 127.0.0.1 (I tried). But if I use my internal network IP (in this case 192.168.1.101) instead of localhost, it successfully connects.

+4
source share
4 answers

Try the following:

 $mysqli = new mysqli("localhost", "user", "pass", "db", 3306); port 
+3
source

you are having problems with your settings

 $mysqli = new mysqli($localhost, $user, $pass, $db); $localhost, $user, $pass, $db (these params should be consistent) 
+1
source

I got an error:

Warning: mysqli_connect (): (HY000 / 1045): access denied for user 'dinesh' @ 'localhost' (using password: YES) in C: \ xampp ..............

I replaced localhost with my IP address and finally worked on Windows 10.

+1
source

I think it should be:

 $mysqli = new mysqli($localhost, $user, $pass, $db); 
-2
source

Source: https://habr.com/ru/post/1491431/


All Articles