I am having difficulty understanding a SSH tunnelling problem. The problem is as follows:

Local Machine --> Intermediate Server --> MySQL Server

The MySQL server can only be accessed from the intermediate server. I have an SSH account for the intermediate server.

How can I connect to the MySQL server from the local machine, specifically from PHP? I want to be able to treat the MySQL server normally, so that I can use PDO with it.

I have tried:

1. Opening ssh (shell\_exec('ssh -L 3307:intermediate-server:3306 username@intermediate-server') ) Honestly not entirely sure if this is correct.
2. Connecting using mysqli on port 3307 (to see if a connection can be made).

It doesn't work, I have tried literally everything I can think of.