PHP PDO MySQL – not using the host specified on DSN

Good evening,

I’ve been trying to struggle on having two database connections in my config file, one being internal and another one being external.

$DB_host = '';
$DB_port = '3306';
$DB_name = 'users';
$DB_user = 'root';
$DB_pass = 'obliquous';

$DB2_host = '';
$DB2_port = '3306';
$DB2_name = 'pancakeshop';
$DB2_user = 'potato_shop';
$DB2_pass = 'ambiguous';

     $db = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
     $db2 = new PDO("mysql:host={$DB2_host};dbname={$DB2_name}",$DB2_user,$DB2_pass);
catch(PDOException $e)
     echo $e->getMessage();

The one I’ve done with – meaning localhost I’ve specified for the dedicated server – it’s working as expected, although, the one with it’s using the local IP address instead of the external one. is the dedicated server the PHP server is running.

The error it’s being given to me it’s the following:

SQLSTATE[HY000] [1045] Access denied for user ‘potato_shop’@’’ (using password: YES)

Is there anything wrong on the code syntax?

This is because root accounts is only for the localhost host (at least, in windows).

Be simpler if you simply create a user with privilege rights to pancakeshop

CREATE USER 'not_root'@'' IDENTIFIED BY 'ambiguous';

GRANT ALL PRIVILEGES ON pancakeshop.* To 'not_root'@'' IDENTIFIED BY 'ambiguous';