title: PDO via SSH2 in PHP?
body: <p>I'm trying to access a remote MySQL Database which is only reachable locally (localhost).</p>
  
  <p>My Code looks like this:</p>
  
  <pre><code>$connection = ssh2_connect('IP to Server', 22);
  
      if (ssh2_auth_password($connection, 'User', 'Password')) {
          echo "Authentication Successful!\n";
      } else {
          die('Authentication Failed...');
      }
  
      $tunnel = ssh2_tunnel($connection, '127.0.0.1', 3306);
  
      try {
          $this-&gt;_connection = new PDO($dsn, $config['login'], $config['password'], $flags);
          $this-&gt;connected = true;
          if (! empty($config['settings'])) {
              foreach ($config['settings'] as $key =&gt; $value) {
                  $this-&gt;_execute("SET $key=$value");
              }
          }
      } catch (PDOException $e) {
          throw new MissingConnectionException(array(
                  'class' =&gt; get_class($this),
                  'message' =&gt; $e-&gt;getMessage()
          ));
      }
  </code></pre>
  
  <p>The script is successful till $tunnel. The PDO connection fails with "Connection refused". I think PDO is trying to connect to MAMP? The $dsn variable looks like "mysql:host=127.0.0.1;port=3306;dbname=mydb". </p>
  
  <p>How can I tell MAMP, that 127.0.0.1 is on the remote server connected through SSH?</p>
  
  <p>Thank you!</p>