I'm trying to access a remote MySQL Database which is only reachable locally (localhost).
My Code looks like this:
$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->_connection = new PDO($dsn, $config['login'], $config['password'], $flags);
$this->connected = true;
if (! empty($config['settings'])) {
foreach ($config['settings'] as $key => $value) {
$this->_execute("SET $key=$value");
}
}
} catch (PDOException $e) {
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => $e->getMessage()
));
}
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".
How can I tell MAMP, that 127.0.0.1 is on the remote server connected through SSH?
Thank you!