Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
moved hardcoded db credentials to config file
  • Loading branch information
eversudip committed Oct 11, 2016
commit 9cf372c0e5c578ee6e9086aa19a184522f24c805
3 changes: 2 additions & 1 deletion appbootstrap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

$config = require('database.php');
require('database/Connector.php');
require('database/QueryBuilder.php');

//return query builder instance
return new QueryBuilder(Connector::make());
return new QueryBuilder(Connector::make($config['database']));
13 changes: 13 additions & 0 deletions database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

return [

'database'=> [
'user' => 'root',
'password' => '',
'dbname' => 'users',
'connection' => 'mysql:host=127.0.0.1',
'options' => []
]

];
9 changes: 7 additions & 2 deletions database/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ class Connector
/**
* Make and return the database connection
*/
public static function make()
public static function make($config)
{
try {
return new PDO('mysql:host=127.0.0.1; dbname=users' , 'root', '');
return new PDO(
$config['connection']. ';dbname='. $config['dbname'],
$config['user'],
$config['password'],
$config['options']
);
} catch(PDOException $e) {
die($e->getMessage());
}
Expand Down