How can I connect to a MySQL database that requires an SSH tunnel using PHP and the Zend Framework?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With