我正试图通过ssh隧道php访问远程mysql。 但是下面的代码授予对我的本地mysql而非远程sql的访问权限。 我如何连接到远程机器
$ssh_server = "server address";
$ssh_port = "22";
$remote_port = "3306";
$ssh_user = "username";
$ssh_pass = "password";
$ssh_conn = ssh2_connect($ssh_server, $ssh_port);
if($ssh_conn){echo "Connection Successful!;}
else{echo 'Connection Failed...';die();}
$ssh_auth = ssh2_auth_password($ssh_conn, $ssh_user, $ssh_pass);
if($ssh_auth){echo "Authentication Successful!";}
else{echo 'Authentication Failed...';die();}
$ssh_tunnel = ssh2_tunnel($ssh_conn, "localhost",$remote_port);
if ($ssh_tunnel){echo "Tunnel created;}
else{echo "Tunnel creation failed!!";die();}
$usr_mysql = "username";
$pwd_mysql = "password";
$host_mysql = "localhost";
$cid_mysql = mysql_connect($host_mysql,$usr_mysql,$pwd_mysql);
if (mysql_error()) {echo mysql_error;die();}