I am getting an apparently common error connecting to my database, however every solution I've tried has not worked in any way. I am getting the following error...
Failed to connect to the database: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
The code I'm using to connect to the MySQL database is:
$username = "root";
$password = "<redacted>";
$host = "127.0.0.1";
$dbname = "siteusers";
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
try {
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
} catch(PDOException $ex) {
die("Failed to connect to the database: " . $ex->getMessage());
}
Currently, the Apache server and MySQL server in question here is managed by xampp running on Windows. I can access everything perfectly fine with phpMyAdmin, however any other way is completely unusable.
Again, everything I've tried hasn't worked. I've tried fiddling with account credentials, localhost/127.0.0.1/etc, trying different users, and changing permission combinations.
RESOLUTION:
I'm not completely sure what I did, but I played with a few settings in my.ini
and things started to work as expected.