Reputation: 753
I'm trying to connect to a remote mysql database with PHP PDO (php version 5.3) and I need it to go through a proxy.
My connection looks like this right now.
$ldb = new PDO("mysql:dbname=users;host=my.remote.host.com", username, password);
I'dd need it to go through a proxy, like http://proxy.mydomain.com:port
I've searched through the PDO Doc and can't seem to find anything on the subject. Is there a way to do it, or am I way off?
Thanks
Upvotes: 3
Views: 2460
Reputation: 361
Complementing Markus answer, here the steps you can follow to tunnel a port through ssh using command line:
ssh -L local_port:database_ip_inside_remote_network:remote_port user@server_with_connection_to_a_dabatase_you_need
example:
ssh -L 3306:10.109.36.4:3306 [email protected]
Now you can use localhost
and the port 3306
inside your php script
Upvotes: 1
Reputation: 804
Not exactly PDO related, but you can tunnel the connection through SSH. Additionally, this offers encryption for your connection. This is especially helpful for getting through proxy or even firewall blocking port 3306. You would then connect to the tunnelled port on localhost.
I am doing this via PuTTY. There are couple of tutorials out there on how to achieve a port tunneling, e.g. from the Kettering University (for mysql it is port 3306 instead of the port 3389 mentioned in this tutorial but the rest is the same)
Upvotes: 1