Forward PHP-application's MySQL-connections towards localhost to a remote server, edit ~/.ssh/config:

Host my-remote-database-server
    LocalForward /var/run/mysqld/mysqld.sock

Do the same, with HAProxy:

    log /dev/log local0 notice
    user haproxy
    group haproxy
    stats socket /var/run/haproxy.stat level admin

    log global
    retries 2
    timeout connect 3000
    timeout server 5000
    timeout client 5000

listen socket
    bind /var/run/mysqld/mysqld.sock mode 666
    option mysql-check user HAPROXY
    balance first
    server mysql-offsite-1 check maxconn 64
    server mysql-offsite-2 check maxconn 64
    server mysql-offsite-3 check maxconn 64

Why not just use the remote hostname or IP in the PHP-applications?

Imagine you have 100 websites, and all of those connect to a specific IP, localhost. Then you need to move out the database server from localhost to somewhere else. This would require changing all the websites configurations...

Another reason, especially with HAProxy, is that you can handle the load-balancing on the webserver instead of inside the PHP-application. Most PHP-applications don't support load-balanced database servers anyway.