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'"));
– Diego
How strange, I did the way you said and the same mistake persisted... Very strange this :/ thanks for the reply.
– Printf
Try this code: <?php Try { $Conn = new PDO('mysql:dbname=database; host=localhost', 'root'); } catch (Pdoexception $e) { print $e->getMessage(); } &##Xa; ?>
– Diego
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.
– Printf
You’re welcome, we’re here :)
– Diego