Error - Connect to Mysql with PDO

Asked

Viewed 362 times

0

I’m trying to connect to a Mysql Database Remotely, through PDO + PHP. Mysql Database is managed by a team, I don’t have access to it. The Database was created and the tables were created. My user gave the appropriate permissions to the bank. However, when I try to connect to it via PHP + PDO it generates the error below:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2005] Unknown MySQL server host 'xxx:3306' (2)' in xxx:8 Stack trace: #0 xxx(8): PDO->__construct('mysql:host=a1-o...', 'user', 'senha') #1 xxx: db_connect() #2 {main} thrown in xxx on line 8

We leave a tcpdump running in the Mysql environment and when we try to connect to the database via PHP, there is no package there. But close telnet on port 3306.

Data from Mysql connection

define('DB_HOST', 'xxx:3306');
define('DB_USER', 'xxx');
define('DB_PASS', 'xxxx');
define('DB_NAME', 'xxx');

    <?php

/**
 * Conecta com o MySQL usando PDO
 */
function db_connect()
{
    $PDO = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8', DB_USER, DB_PASS);

    return $PDO;
}



?>

Someone could help me?

    1. Port 3306 and default you can omit it. 2) DSN is in the following format "mysql:host=xxxx;port=3306;dbname=xxx", you did not add ";port="
  • @Anderson, I just tested with your suggestion/guidance and the same error occurred: Can’t connect to Mysql server . Localhost works, but setting a remote mysql gives this error. Do I need to force php to fill a remote mysql? I left a tcpdump running to the destination and no package comes out there.

  • the error messages are different: "QLSTATE[HY000] [2005] Unknown Mysql server host" other "Can’t connect to Mysql server", you may be restricted from "host name", try to perform below procedure to test your host name permission.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.