CodeIgniter Forums
Establishing SSH Tunnel to Connect to Remote MySQL Database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Establishing SSH Tunnel to Connect to Remote MySQL Database (/showthread.php?tid=58594)



Establishing SSH Tunnel to Connect to Remote MySQL Database - El Forum - 06-27-2013

[eluser]Unknown[/eluser]
I am refactoring a spaghetti code PHP application into the Codeigniter framework and the development version of the application is on a different server than the production database. For testing, I would like to establish an ssh tunnel from my EC2 instance where I am hosting the development version to the production database. I have successfully created an ssh connection with the remote server via libssh2 AND with phpseclib (http://phpseclib.sourceforge.net/). However, after the ssh tunnel has been established, I am not able to connect to the database with the codeigniter mysqli db driver.

With every attempt to connect to the database, I get the following error:

Unable to connect to your database server using the provided settings. Filename: core/MY_Controller.php Line Number: 6

The MY_Controller code is:

1 <?php defined('BASEPATH') OR exit('No direct script access allowed');
2
3 class MY_Controller extends CI_Controller {
4
5 public function __construct() {
6 parent::__construct();
7 $this->auth = new stdClass;
8 $this->load->library('flexi_auth');
9 if (!$this->flexi_auth->is_logged_in()) {
10 header('Location: /login');
11 }
12 }

I have modified the mysqli driver to include the tunnel object as a parameter in the mysqli real_connect function as follows, to no avail. Does anyone know how I can make this work?

Thank you in advance for any help!

Mike


Establishing SSH Tunnel to Connect to Remote MySQL Database - El Forum - 07-16-2014

[eluser]clustersblue[/eluser]
Hi mpduffey,

Were you able to get this to work? I also successfully created a ssh connection but when I load my codeigniter database I get the same error with you.