SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost'
<p>I'm trying to connect with a database, but I got this message :</p>

<blockquote>
  <p>SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost'
  (using password: YES)</p>
</blockquote>

<p>I'm connecting to MySQL via phpMyAdmin using <code>root</code> as username and <code>toor</code> as the password.</p>

<p>This is my code:</p>

<pre><code>&lt;?php


class DB
{
    private $host = '127.0.0.1';
    private $username = 'root';
    private $password = 'toor';
    private $database = 'shoppingtheme';
    private $db;

    public function __construct($host = null, $username = null, $password = null, $database = null) {

        if($host != null)
        {
            $this-&gt;host = $host;
            $this-&gt;username = $username;
            $this-&gt;password = $password;
            $this-&gt;database = $database;
        }

        try {
            $db = new PDO('mysql:host='.$this-&gt;host.' ; dbname = '.$this-&gt;database, $this-&gt;username, $this-&gt;database, array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt; 'SET NAMES UTF8'));
        } catch (PDOException $e) {
            die($e-&gt;getMessage());
        }

    }


}
</code></pre>
