the connect functions (which, depends on your db type: mysql, postgres, oracle, ...) have an optional hostname parameter where you can specify on which host the db resides that you want to connect to.
furthermore, your web host should be granted access to the db.
check out your connect function in the reference.