Search code examples
phpmysqlportforwarding

Using port forwarding and php with mysql_connect onto a remote server


I've got a web server with one host, and I'd like to use the database on another host. I'd like to use port forwarding to do this, and have already set up the forwarded port using

ssh -P -fg -L23307:myserver.net:3306 [email protected] sleep 1d

This seems to be working properly (although if someone could tell me how to check, that would be great), but I can't get PHP to connect to MySQL through that port - it keeps trying to connect to its own local MySQL database (which isn't running).

$mlink = mysql_connect( "localhost:23307", "myusername", "mypassword" );
mysql_select_db( 'mydatabase', $mlink ) or die ( "Error - cannot connect to database localhost:23307.<br />Error: ".mysql_error() );  

As you can see, I'm not doing anything that complicated, so why does it keep trying to connect locally?


Solution

  • So, turns out the answer was "don't trust people when they say they've opened the port on the firewall".

    Anyone want a job?