I've just started studying PHP and having concluded my first PHP & MySQL for dummies book I have a concern about having a secure connection between my PHP application and MySQL database.
From what I learned, one approach is to create a .php file with the database credentials, for example:
--- database.php ---
<?php
define('HOST', 'localhost');
define('DB_USR' , 'mysql_username');
define('DB_PSWD' , 'mysql_password');
define('DB_NAME' , 'mysql_newbie');
?>
and then place a require_once('database.php')
in every PHP page that requires any sort of database queries.
My concern is whether this approach is safe. Isn't the file database.php accessible to everyone once it's placed on the webserver?
Anyone can potentially read the database's credentials and mess his way around it?
Any thoughts?