It's secure as long as nobody can access the text contents of test.php. A reasonable best practice would be to store the credentials somewhere that's not accessible by a visiting user, so that if for instance the contents of example.com are put in a folder /some/path/to/www-data, you could put the file somewhere else, like /some/path/to/credentials.php. That way, the web server can still load the file, but external users won't be able to access it.
In addition, while we're discussing MySQL/PHP best practices, please note that the mysql_ functions have been deprecated, and for good reason. Instead, I suggest you use mysqli_ (where the i stands for improved), or PDO. You can read more about it here: How can I prevent SQL injection in PHP?