Hmmm ... that sounds like something you shouldn't do at all. Write an API that resides in a remote database that you can access.
If you insist on direct access to the database. Hard host code, username and password in the file, put the file outside the document root and include it from there. For example, if your document root directory (for example, the Drupal index.php file) was / www / htdocs, put the file containing the information on something like / www / secure and include it where you need it. Then, if php stops working for some reason, the file is not in a readable place in the outside world, but PHP can include it on the site as needed.
Of course, someone can see that you included the file, but they would not be able to see the file itself, unless they had hacked your server (and not just Drupal), and in this situation you screwed up anyway.
source share