Warning: mysqli_connect(): (HY000/1045): Access denied for user \'username\'@\'localhost\' (using password: YES) in C:\\Users\\xampp\\htdocs\\PHP_Login_Script
Use this
After setup this you will not receive this issue again
SET PASSWORD FOR root@localhost = PASSWORD('your_root_password');
I was stuck up in this issue after used this query everything was solved
Try the above answers 90% of the time this will be you issue. For me my problem was that my database password had a $ in it.
$servername = '127.0.0.1';
$username = 'user_bob';
$password = 'sdfasdf$B';
$conn = mysqli_connect($servername, $username, $password, 'any_database');
//DO NOT USE DOUBLE QUOTES;
//$password = "sdfasdf$B";
The question has been answered above, Just to make you feel comfortable using all four string at the same time in a connection
<?php
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASSWORD", "");
define("DB_DATABASE", "databasename");
$db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
// you could test connection eventually using a if and else conditional statement,
// feel free to take out the code below once you see Connected!
if ($db) {
echo "Connected!";
} else {
echo "Connection Failed";
}
?>
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
Put " DB_HOST " instead of " DB_SERVER " also
put " DB_USER " Instead of " DB_USERNAME "
than it working fine !
If youre running wamp update
define("DB_HOST", "localhost");
To your machines ip address (mine is 192.168.0.25);
define("DB_HOST", "192.168.0.25");
You can find it on window by typing ipconfig in your console or ifconfig on mac/linux
you defIne as DB_USER but use as DB_USERNAME. Also php says username@localhost cant access. Not root@localhost.
Change your define or connect paramater.