I need to connect to a remote MySQL server with PHP but I get the following error:
Warning: mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on ... (13) in /var/www/html/index.php on line 16
Warning: mysqli::query(): Couldn't fetch mysqli in /var/www/html/index.php on line 17
Fatal error: Call to a member function fetch_assoc() on a non-object in /var/www/html/index.php on line 18
The remote server firewal is open, user has permission to connect from any Host, and I'm able to connect from the local server with mysql command line, but not able to connect with PHP.
What may be the problem here?
EDIT: Already tried with different connection code, but always same error.
This is the latest one:
$mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS msg");
$row = $result->fetch_assoc();
echo $row['msg'];