How to connect to mysql database on another server using php

How to connect to mysql database on another server using php

Find out the IP address of the server A where your scripts will be uploaded. Do not forget to change the localhost to the ip address of the Server B in mysql_connect() or mysqli_connect() method.
Now go the control panel of the Server B where your Database is hosted.

In the control panel’s Homepage go the databases section and click the Remote MYSQL option.

Then add the Ip address of the Server A and click on add host.This will whitelist the Ip to connect mysql

Now you can access to the database in Server B while your scripts are running in Server A. Mind you the fetched result will be slow cause it is getting data from database that is located on another server.