When I try to connect to my external server (which has allowed external connections) from my WAMP Server installation using this code:
const SERVER = 'xxx.xxx.xxx.xx'; // Redacted, the target servers IP
const PORT = 3306;
const DATABASE = 'xxx'; // Redacted
const USERNAME = 'xxx'; // Redacted
const PASSWORD = 'xxx'; // Redacted
const TIMEOUT = 5;
try
{
$pdo = new PDO('mysql:dbname=' . DATABASE . ';host=' . SERVER . ';port=' . PORT, USERNAME, PASSWORD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_TIMEOUT => TIMEOUT));
}
catch (PDOException $e)
{
echo $e->getMessage();
}
I get the following error message:
SQLSTATE[HY000] [1045] Access denied for user 'main'@'xxx.xxx.xxx.xx' (using password: YES)
where the IP address is my external (not LAN) IP address instead of the one that I specified.
I have tried this code before and it worked without any problems, but now suddenly for reasons that remain unknown to me, it attempts to connect to my own IP and fails. What am I doing wrong?
I was having exactly the same issue with my root and other users. I was trying to connect to remote server A from another remote server B using PDO(). Although, I was able to login to mysql remote server A from remote server B using CLI but not through PDO.
Both remote server were running:
The problem was special characters in my root and user password. There were #, (, !, )
. So I changed my passwords and it started working.
I literally scanned the whole internet for two days to solve this problem. Didn't know it could be password.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With