--- a/classes/bfw/Configuration.php
+++ b/classes/bfw/Configuration.php
@@ -7,6 +7,8 @@
namespace bfw;
+use PDO;
+
class Configuration {
/**
@@ -47,4 +49,16 @@
)
);
}
+
+ /**
+ * @return array
+ */
+ public static function getDataSourceProperties() {
+ return array(
+ 'dsn' => 'mysql:host=localhost;dbname=bfw',
+ 'config' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'),
+ 'username' => 'bfw',
+ 'password' => 'bfw',
+ );
+ }
}
\ No newline at end of file
--- a/classes/bfw/database/Database.php
+++ b/classes/bfw/database/Database.php
@@ -7,6 +7,7 @@
namespace bfw\database;
+use bfw\Configuration;
use Logger;
use PDO;
use PDOException;
@@ -22,9 +23,14 @@
private function __construct() {
$this->logger = Logger::getLogger(__CLASS__);
- $dsn = 'mysql:host=localhost;dbname=ticketsystem';
- $config = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
- $this->pdo = new PDO($dsn, 'ticketsystem', 'ticketsystem', $config);
+ $cfg = Configuration::getDataSourceProperties();
+
+ $dsn = $cfg['dsn'];
+ $config = $cfg['config'];
+ $username = $cfg['username'];
+ $password = $cfg['password'];
+
+ $this->pdo = new PDO($dsn, $username, $password, $config);
}
/**