I have a problem connecting to my mysql database on another server from my VPS, connecting to localhost mysql works fine. This is my PHP script:
<?php
$servername = "mysql.example.com";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=database", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
I am getting this error: SQLSTATE[HY000] [1045] Access denied for user 'username'@'fh24-219.cybersales.cz' (using password: YES)
The problem is propably that host changed from mysql.example.com
to fh24-219.cybersales.cz
(it points to my VPS ip). I have no idea why. I have already changed httpd_can_network_connect_db
and httpd_can_network_connect
to 1
. I would appreciate some help. I can connect to mysql.example.com
with phpmyadmin. Thanks.