I'm trying to connect one linux server to another linux server's mysql db using the PHP function ssh_tunnel().
Background:
I can access the linux server's mysql db on my Mac by typing in the command line:
Code:
ssh username@serverIP -L 3307:192.168.0.100:3307
Then I use CocoaMySQL to access the DB.
Current:
I want to do about the same thing with PHP to connect one linux server to the other linux server's mysql db. Here's what I've tried:
PHP Code:
$connection = ssh2_connect('serverIP', 22);
if (ssh2_auth_password($connection, 'username', 'secret')) {
echo "Authentication Successful!\n";
} else {
die('Authentication Failed...');
}
print"<br><br>";
if(function_exists("ssh2_tunnel"))
echo "success";
else
echo "failure";
print"<br><br>";
$tunnel = ssh2_tunnel($connection, '192.168.0.100', 3307);
$conn = mysql_connect('127.0.0.1', 'DBusername', 'DBpassword' ) or die (mysql_error());
The ouput I get is:
HTML Code:
Authentication Successful!
success
Access denied for user 'DBusername'@'localhost' (using password: YES)
But If I change the username and password to the local mysql username and password, then I get access to the local mysql db but not the remote mysql db.
Any ideas how to connect to the remote server, through ssh, and use the mysql_connect() function?