0

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.

Treyzania
  • 103
  • 6
  • That is clearly **not** the code you're using to connect to the database, since it mentions a different username in the error message. Check the permissions for the user `sitephp` - that's the one that's trying to connect. – Kryten Jul 18 '14 at 15:23
  • Ever tried to connect to the mysql server via command line to verify that it's not a problem with your user credentials? ’mysql -p’ ? – Daniel K. Jul 18 '14 at 15:24
  • The user in the error message doesn't matter, it always happens, no matter the user. When I connect via the command line, there is no errors. – Treyzania Jul 18 '14 at 15:36

0 Answers0