0

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 :)

9
  • 1
    does the user test have permission to access test db? Commented Apr 10, 2019 at 14:39
  • 1
    You should update your title since it isn't the same error message as in your question. Commented Apr 10, 2019 at 14:39
  • @MasivuyeCokile yes he has Commented Apr 10, 2019 at 14:40
  • @MagnusEriksson ? it's the same error message ^^ Commented Apr 10, 2019 at 14:41
  • 1
    Can you access the database with the same user/pass via the command line? Commented Apr 10, 2019 at 14:52

2 Answers 2

1

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 ! :)

Sign up to request clarification or add additional context in comments.

Comments

0
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

4 Comments

There's no real difference between your code and the OP's code.
There is no difference, because he said he wanted to connect PDO and what I did is pdo.
Ty, Il try this tomorrow :)
Works like magic, thanks for the tip. I had the same issue with different production servers...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.