• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SSH2 Tunnel with external MySql Connection

#1
Hi,
i need an external MySQL connection over ssh tunnel.

I have two servers. On server 1 ssh2 as php-module is installed.
On server 2 is the db i want to connect to.

My code on server 1 is:
PHP Code:
$connection ssh2_connect('www.server2.de''22');
 
       if (ssh2_auth_password($connection'user','pass')) {
 
           echo "Authentication Successful!\n";
 
       } else {
 
           die('Authentication Failed...');
 
       }

 
       $tunnel ssh2_tunnel($connection'127.0.0.1'3308); 
Result:
Authentication Successful!
$tunnel is stream!

And now i want to connect to the external Db on server 2 with this options:
$db['dbold']['hostname'] = "127.0.0.1";
$db['dbold']['port']     = 3308;
$db['dbold']['username'] = "xxxx";
$db['dbold']['password'] = "xxxx";
$db['dbold']['database'] = "migration";
$db['dbold']['dbdriver'] = 'mysqli';
$db['dbold']['dbprefix'] = '';
$db['dbold']['pconnect'] = TRUE;
$db['dbold']['db_debug'] = TRUE;
$db['dbold']['cache_on'] = FALSE;
$db['dbold']['cachedir'] = '';
$db['dbold']['char_set'] = 'utf8';
$db['dbold']['dbcollat'] = 'utf8_general_ci';
$db['dbold']['swap_pre'] = '';
$db['dbold']['autoinit'] = FALSE;
$db['dbold']['stricton'] = FALSE;

But this doesn't work.
CI says:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 353

Does somebody has any idea?
Reply

#2
i use auto ssh. Keeps the connection up permanently too, which is a bonus.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.