(Assuming *nix/Apache running PHP as a module)
This is a common problem.
If you have a dedicated server:
Put the pass/id-file in a location outside the webservertree.
ie your homedir or /etc/httpd/db.conf.
This way PHP can reach it but you can't get it with at external webbrowser.
If your on a ipbased-virtualserver. Put the id/pass-file in your homedir. Ask the serveradmin to put the User and Group stuff into the httpd.conf so that the webserver run as your uid/gid (prob allready done). "chmod 700" on the id/pass-file.
The real problem starts when you have your site on a namebased-virtualserver.
Then you can't get the server to run as a seperate user for each domain.
Still if you trust the other users on the server. Put the id/pass-file outside the reach of a webbrowser-request and make the file readable to the webserver-user(nobody?).
The flaw in this is that any user on the server capable on writing a php-script can access the id/pass-file throw a simple "exec('cat /home/someuser/db.conf')"
If somebody has a good solution on how to suid the execution of a phpscript or running namebased virtualhosts as seperate users please let me know cause I really need it aswell.