How to connect to a mysql database from another network through PHP?

I would like to make a PHP connection to the MYSQL database that is on another computer in another network. I have the external IP of that machine that hosts the database and I made the following PHP connection:

However, it does not work …
I have tried in another way:

getMessage ());

The following error message appears with this code SQLSTATE[HY000] [2006] MySQL server has gone far