'Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

When I try to run my php code on localhost, then error given given below appears:

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) in C:\xampp\htdocs\Final Project CSE-391\project\config.php:2 Stack trace: #0 C:\xampp\htdocs\Final Project CSE-391\project\config.php(2): PDO->__construct('mysql:host=loca...', 'root', '') #1 C:\xampp\htdocs\Final Project CSE-391\project\index.php(2): include('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\Final Project CSE-391\project\config.php on line 2strong text

I need suggestion to solve this issue.



Solution 1:[1]

This is a wrong credential issue. Check the values you used on the browser to log into PHPMyAdmin to ensure it is correct before putting it in the connection config.

You could have entered the wrong password or leaving password to blank after having set a password.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Kariuki