Reputation: 11
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:
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!
Upvotes: 1
Views: 121
Reputation: 80
Your code is correct, I have tested it with my database. Only small typo error is there, catch(PDOException §e)
have the wrong character '§' instead of '$'
Upvotes: 1