There are a lot of ways to handle this sort of thing; some involve external configuration files, some don't.
One way is to always run the database programs on the same machine as the database server; this means that you can just connect to "localhost", and reach the right database.
Another method is to have your program detect which host you're running on, and set the database on that basis: when running on machine 'prod', connect to 'prod_database', when running on machine 'test', connect to 'test_database', and so forth.
You can also just do your database configuration in your DNS and/or /etc/hosts file; a configuration system that you (or your sysadmin) is probably already using. In this method, you always connect to the host "database_server": but that hostname points to different IP addresses on different on different machines.
Or, as you pointed out, you can just use any number of the other config file methods to specify different results on different machines.... do whatever works for you...