LeRouteur
LeRouteur

Reputation: 145

MySQL error: SQLSTATE[HY000] [1045] Access denied for user 'test'@'localhost' (using password: YES)

I'm actually making a form in PHP with MVC2. In my model, I need to connect to a local MySQL database. I do this with PDO. Here is my dsn :

mysql:host=localhost;dbname=test-heia;charset=utf8mb4', "test", "test"

But when I try to access my model through Chrome, I got this error (with PDOException) :

SQLSTATE[HY000] [1045] Access denied for user 'test'@'localhost' (using password: YES)

I'm sure of the user/password. I also tried with root user, but it doesn't seems to work.

It's not like the proposed answer, because it's on a web page :)

Could you please help me ? Thank you in advance :)

Upvotes: 0

Views: 18710

Answers (2)

LeRouteur
LeRouteur

Reputation: 145

I resolved the problem. The path to the socket of MySQL wasn't enabled (see here). Once I put it, it worked.

Thank's all for the answers ! :)

Upvotes: 1

paki leonel
paki leonel

Reputation: 94

define('DBHOST', 'localhost');
define('DBUSER', 'test');
define('DBPASS', 'test');
define('DBNAME', 'test');

try {
    $bd= new PDO('mysql:host='.DBHOST.';dbname='.DBNAME,DBUSER,DBPASS);
}catch(Exception $e)
 {
    die('Erreur : '.$e->getMessage());
 }

Try it with that

Upvotes: 0

Related Questions