how to acces remote mysql db from localhost?

  cpanel, mysql, php

here is my connection file which works fine if I’m on remote url (https://example.com)

define('DBHOST','example.com');
define('DBNAME','example_db');
define('DBUSER','example_user');
define('DBPASS','example_pass');
    
try {
    $db = new PDO("mysql:host=".DBHOST."; dbname=".DBNAME, DBUSER, DBPASS);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
catch (PDOException $e) {
    echo $e->getMessage();
    exit;
}

$db->query('SET character_set_client = "utf8"');
$db->query('SET character_set_results = "utf8"');
$db->query('SET collation_connection = "utf8_general_ci"');

error_reporting(E_ALL);
ini_set('display_errors', 'on');

I need to access the remote database from localhost (win7, xampp, chrome) and I found this tutorial
On cpanel – in the input named Add Access Host – I write may domain like – example.com and click the button Add Host
An info page says – succesfull – go to back
Going back and can’t see any changes, any added domain on any list or simillar
In the section Manage Access Hosts I see two rows – 185.119.88.70 and 77.243.27.58
In chrome while trying to load index.php from localhost – there is a message – SQLSTATE[HY000] [1045] Access denied for user...
Any help – how to acces remote mysql db from localhost?

Source: Ask PHP

LEAVE A COMMENT