Skip to content
Advertisement

Use proxy to connect to a mysql db through PDO

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

Advertisement

Answer

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)

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement