How can I connect to a MySQL database that requires an SSH tunnel using PHP and the Zend Framework?
+4
A:
Just start up SSH tunnel and use the local port as your MySQL port.
For example, you start tunnel as this,
ssh -f [email protected] -L 3306:mysql-server.com:3306 -N
And you can connect to MySQL like this,
$conn = mysql_connect('localhost', 'mysql_user', 'mysql_password');
For zend_db, you do this,
$config = new Zend_Config(
array(
'database' => array(
'adapter' => 'Mysqli',
'params' => array(
'host' => 'localhost',
'dbname' => 'my_db',
'username' => 'mysql_user',
'password' => 'mysql_password',
)
)
)
);
$db = Zend_Db::factory($config->database);
ZZ Coder
2010-05-10 23:45:33
I'm getting a "connection refused" message. It's also saying that it's connecting on port 22 which doesn't make sense since I am specifying the two ports...do you know why this isn't working for me?
Andrew
2010-05-11 14:52:16
The error means you don't have SSH running on the server. It has nothing to do with MySQL.
ZZ Coder
2010-05-11 15:01:04
ah, turns out it was an issue with the way I was connecting via ssh.
Andrew
2010-05-11 16:57:23