php - SQLSTATE[28000] [1045] Access denied for user 'root’@host -



php - SQLSTATE[28000] [1045] Access denied for user 'root’@host -

couldn't access database error message:

sqlstate[28000] [1045] access denied user 'root’@‘xxx.ne.jp'(using password: yes)

i have php code.

$dsn = 'mysql:dbname=mydb;host=xxx.ne.jp'; $user = 'root'; $password ='0123'; try{ $dbh = new pdo($dsn, $db_user, $db_password); $dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception); } grab (pdoexception $e) { echo $e->getmessage(); }

i can login phpmyadmin same username , password(root/0123). why? have thought prepare it?

here basic pdo connection example:

$dbh = new pdo('mysql:host=localhost;dbname=test', $user, $pass);

so include missing host name:

$dsn = 'mysql:host=localhost;dbname=mydb;host=xxx.ne.jp'; $user = 'root'; $password ='0123'; try{ $dbh = new pdo($dsn, $db_user, $db_password); $dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception); } grab (pdoexception $e) { echo $e->getmessage(); }

change localhost if running site on host.

php mysql pdo

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -