I have a problem with a Database Connection. It sounds really simple, but I have been searching for a solution for a while now...
My Server:
- Ubuntu 16.04
- Apache 2
- PHP 7.0.15
I put this PHP script into /var/www/html and gave it chmod 744 / 755 for testing.
try {
$pdo=new PDO ('mysql:dbname=test;host=ip-address', 'user', 'password');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'Verbindung fehlgeschlagen: ' . $e->getMessage();
}
But when I call this file in my browser, the following message shows up:
SQLSTATE[HY000] [2002] Connection refused
The Database User has every rights. I also tried the root user.
Can anyone help me with this one? What could be the problem? I can't find an answer.
Thanks - Flo!
$pdo=new PDO ('mysql:host=ip-address;dbname=test', 'user', 'password');PDOExceptionand replace it byExceptionand tell us what is giving. Apart of that, the error is saying that the Database is rejecting your connection. If you are not in alocalhostthen you must open ports and configuration to allow that. If you are inlocalhost, maybe you have wrong user permissions to that Database. About the rights on the user, you can add rights for any IP or for a fixed IP.