I am doing a CRUD project, I have my database connectivity parameters saved in a file called conn.php its code is given below
<?php
$conn = @mysql_connect('127.0.0.1','root','');
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mt', $conn);
?>
I am linking this file wherever I need database connectivity using the include function like this
<?php
include 'conn.php';
?>
But I am just wondering if this is not a security breach, I mean anyone can write their code and just include that connectivity file and then be able to operate on my database.
How do I stop this? I know not using the conn.php and writing the database connectivity code into each and every php page that needs to work with the database can solve this, but then there is the problem that if I ever need to change the database connectivity parameters then I will have to change those in each and every file that needs to work with the database, and that is not feasible, as I might end up having hundreds of such files. So what is the way around this?