As mentioned by other respondents, this should usually not be a problem, as users will not be able to see the PHP code. If, however, you plan to share the code with others, it may be a bit of a hassle to remove the username and password before sending it to someone (and if you forget that they will recognize your password).
So you can put the information in a file and then read it in PHP. For example, create a file with a name mysql.iniin your home directory and put the following information in it:
host = "127.0.0.1"
username = "user"
password = "pass"
database = "db"
Then read it in PHP and plug in, for example:
$settings = parse_ini_file('/home/mysql.ini');
mysql_connect($settings['host'], $settings['username'], $settings['password'], $settings['database']);
Remember to make sure that the file is located in a section of the web server that is not publicly accessible, otherwise people will be able to read your registration information.
source
share