Zend_Db: How to connect to MySQL database through SSH tunnel?

How can I connect to a MySQL database that requires an SSH tunnel using PHP and Zend Framework?

+4
php mysql ssh zend-framework
May 10 '10 at 23:27
source share
2 answers

Just start the SSH tunnel and use the local port as your MySQL port.

For example, you start a tunnel like this,

ssh -f user@mysql-server.com -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); 
+8
May 10 '10 at 11:45 a.m.
source share

Is there a way to establish this to create a permanent connection, either in the apache2 configuration or through Zend, so that it connects if necessary from the server and remains open for a certain period of time in case subsequent calls come in?

0
May 17 '12 at 16:12
source share



All Articles