PDO mysql and PHP error

Asked

Viewed 56 times

0

I already 'decoded' the php.ini file for the PDO to work, restarted several times apache, mysql, notebook, but I can’t connect to Mysql database.

Use Windows 7. Worst I installed a virtual machine on another PC with UBUNTU 14 and the same error happened.

Can anyone tell me what it is?

The user and password are correct, it is the same user of the bank that I created.

Follow the connection code:

<?php
  try {
    $conn = new PDO("mysql:host=localhost; dbname=nomebanco user=root password=123456");

} catch (PDOException $e) {
    print $e->getMessage();

}

?>

Error:

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

  • Dude, your mistake already says the solution: Access denied for user ''@'localhost' (using password: NO). Delete the password, leave only quotes, like: $connected = new PDO('mysql:dbname=reservations;host=localhost', 'root', ', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));

  • How strange, I did the way you said and the same mistake persisted... Very strange this :/ thanks for the reply.

  • Try this code: <?php Try { $Conn = new PDO('mysql:dbname=database; host=localhost', 'root'); } catch (Pdoexception $e) { print $e->getMessage(); } &##Xa; ?>

  • Damn it, it worked!! I think it was an error in the order of the code or something, I used the code you gave me, but I didn’t leave it without a password, I put the password in the code, instead of the '', and the connection worked fine... Man, thank you so much for your attention and for helping me solve the problem! Good weekend, see you.

  • You’re welcome, we’re here :)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.