title: SQLSTATE[HY000] [2002] Operation timed out
body: <p>I am creating a pdo data connection. The connections works fine on localhost. 
  But when I connect to my remote db, and use exactly the same credentials which I have used before, I get a empty page, no error messages, just a empty page.</p>
  
  <p>The same credentials that are working on a previous project were done with mysqli, this one is done with pdo.</p>
  
  <p>I have tried two types of pdo connection code, none of them are working.</p>
  
  <p>First one:</p>
  
  <pre><code>$databaseHost = 'x.xxx.xxx.xx';
  $databaseName = 'xxxxxxxxx';
  $databaseUsername = 'xxxxxxx';
  $databasePassword = 'xxxxxx';
  $charset = 'utf8';
  
  try {
  
      $dsn = "mysql:host=$databaseHost;dbname=$databaseName;charset=$charset";
  
  
  } catch(PDOException $e) {
      echo 'Connection failed: ' . $e-&gt;getMessage();
  }
  
  $opt = [
      PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION,
      PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_ASSOC,
      PDO::ATTR_EMULATE_PREPARES =&gt; false,
          ];
  
  $pdo = new PDO($dsn, $databaseUsername, $databasePassword, $opt);
  </code></pre>
  
  <p>Second one:</p>
  
  <pre><code>$databaseHost = 'x.xxx.xxx.xx';
  $databaseName = 'xxxxxxxxx';
  $databaseUsername = 'xxxxxxx';
  $databasePassword = 'xxxxxx';
  
  $opt = [
      PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION,
      PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_ASSOC,
      PDO::ATTR_EMULATE_PREPARES =&gt; false,
          ];
  
  try {
  
      $pdo = new PDO("mysql:host={$databaseHost};dbname={$databaseName}", $databaseUsername, $databasePassword, $opt);
  
      } catch(PDOException $e) {
      echo 'Connection failed: ' . $e-&gt;getMessage();
    }
  </code></pre>
  
  <p>Even though both connections work in localhost, I tried to just load this connection page locally in the browser, the fist option gave me this error:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Operation
    timed out in /Applications/MAMP/htdocs/ijdb_pdo/config.php:24 Stack
    trace: #0 /Applications/MAMP/htdocs/ijdb_pdo/config.php(24):
    PDO->__construct('mysql:host=83.1...', 'u1164707_sohail', 'sohail123',
    Array) #1 {main} thrown in
    /Applications/MAMP/htdocs/ijdb_pdo/config.php on line 24</p>
  </blockquote>
  
  <p>and the second option gave me the following error:</p>
  
  <blockquote>
    <p>againtestConnection failed: SQLSTATE[HY000] [2002] Operation timed out</p>
  </blockquote>
  
  <p>What am i messing up in my code?</p>
  
  <p>I tried then to connect through the terminal with:</p>
  
  <pre><code>MacBook-Pro-3:/ sohail$ /Applications/MAMP/Library/bin/mysql -h "xx.xxx.xxx.xx" -u "xxxxxx" "-pxxxxxxx" "xxxxxxx";
  </code></pre>
  
  <p>and got the following error:</p>
  
  <blockquote>
    <p>Warning: Using a password on the command line interface can be
    insecure. ERROR 2003 (HY000): Can't connect to MySQL server on
    'xx.xxx.xxx.xx' (60) MacBook-Pro-3:/ sohail$</p>
  </blockquote>
  
  <p>I don't think I have terminal access on my remote machine, so I can't do SHOW GLOBAL VARIABLES LIKE 'PORT'; cmd
  -thanks</p>