php - Where should the credentials for mysql be put? -
logging mysql database requires credentials. have these credentials in php class called class.dbone.php
.
this in git repo on server. use push deploy.
i want share repo contract devs, don't want them have access credentials.
how mitigate this?
are credentials supposed be?
here snippet:
<?php // creates 1 instance of database class dbone { private $db_user = 'foo'; private $db_pass = 'foo'; private $db_driver = 'mysql:dbname=foo;host=localhost'; // singleton uses static variable ensure 1 instance @ time private static $database; private function __construct() { $this->checkforcleardb(); // self::checkforclearpostgres(); try { // instaniate database connection self::$database = new pdo( $this->db_driver, $this->db_user, $this->db_pass ); } catch( pdoexception $pdoerror ) { echo 'pdo connection failed: ' . $pdoerror->getmessage(); } }
move credentials separate file, , keep content simple possible, variable assignments, this:
<?php $db_user = 'foo'; $db_pass = 'foo'; $db_driver = 'mysql:dbname=foo;host=localhost'; ?>
and don't add file in version control. add sample file instead, developers should customize local dev database.
when use these variables in file, have indicate in global scope using global
keyword, example:
global $db_user, $db_pass, $db_driver;
Comments
Post a Comment