Source: http://stackoverflow.com/questions/14952853/how-to-secure-database-configuration-file-in-project
You can try to put your database credentials in separate file with proper UNIX permissions set, for example 644, and then include this file on top of your script.
The
configuration.php
file will look like:<?php
define (DB_USER, "mysql_user");
define (DB_PASSWORD, "mysql_password");
define (DB_DATABASE, "database_name");
define (DB_HOST, "localhost");
?>
Your original script will look something like this:
require ("configuration.php");
public class DatabaseConnect
{
function __construct()
{
mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die('Could not connect to MySQL server.');
mysql_select_db(DB_DATABASE);
}
}
Comments
Post a Comment