There are a couple ways you can do it. You could look to see if the $_SERVER['HTTP_HOST'] is "localhost" or not. If it is, then you know you're "debugging" and should use "localhost" as your MySQL server; otherwise, use the remote MySQL host.
I personally like to set a flag in a config file that way there's no "chance" of anything breaking and something not working right. Usually I call it "$debug" and it's boolean, so if it's true, use "localhost" otherwise use remote servers.
And finally there's the ability to set up a configuration file which has two sections, one for debugging/testing and the other for production. You could use your own config reader or part of the Zend Framework to read the configuration file, and then just use the part you want.
With Zend_Config you would use something like:
$section = 'debug'; // Change to production when you want to run it in production
$config = new Zend_Config_Xml('config.xml', $section);
Just a few options to choose from.