Skip to content

Commit e84e9c1

Browse files
authored
Merge pull request #7 from pidusanirhs/development
moved hardcoded db credentials to config file
2 parents eaba690 + 9cf372c commit e84e9c1

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

appbootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3+
$config = require('database.php');
34
require('database/Connector.php');
45
require('database/QueryBuilder.php');
56

67
//return query builder instance
7-
return new QueryBuilder(Connector::make());
8+
return new QueryBuilder(Connector::make($config['database']));

database.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
return [
4+
5+
'database'=> [
6+
'user' => 'root',
7+
'password' => '',
8+
'dbname' => 'users',
9+
'connection' => 'mysql:host=127.0.0.1',
10+
'options' => []
11+
]
12+
13+
];

database/Connector.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ class Connector
55
/**
66
* Make and return the database connection
77
*/
8-
public static function make()
8+
public static function make($config)
99
{
1010
try {
11-
return new PDO('mysql:host=127.0.0.1; dbname=users' , 'root', '');
11+
return new PDO(
12+
$config['connection']. ';dbname='. $config['dbname'],
13+
$config['user'],
14+
$config['password'],
15+
$config['options']
16+
);
1217
} catch(PDOException $e) {
1318
die($e->getMessage());
1419
}

0 commit comments

Comments
 (0)