Reputation: 3207
I am trying to connect to the database using PDO with IP address as host, but I get this error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000] [1044] Access denied for user 'xxx'@'%' to database 'ddd'' in /Applications/MAMP/htdocs/iravin/testconnect.php:31 Stack trace: #0 /Applications/MAMP/htdocs/iravin/testconnect.php(31): PDO->__construct('mysql:host=162....', 'xxx', 'zzz') #1 {main} thrown in /Applications/MAMP/htdocs/iravin/testconnect.php on line 31
While if I used the dns "xxx.com" as host, it will work normally.
Here's my code for connection:
$con = new PDO('mysql:host=123.123.123.12;dbname=xxx', 'zzz', 'ccc');
Upvotes: 2
Views: 5396
Reputation: 11
try {
$con = new PDO('mysql:host=123.123.123.12;dbname=xxx', 'zzz', 'ccc');
$handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "The Following error has occurred:".$e->getMessage()."";
}
Check that your username, database name and password are correct. The IP address is fine as it has said the user has been denied access which means it isn't the IP.
Upvotes: 1
Reputation:
It seems like more of a permission issue for the user. It looks like it has access for the domain xxx.com, but not for the ip address. Make sure the user has rites for the ip address as well.
Upvotes: 1