Datenbank ist jetzt frei konfigurierbar
authorMarkus Bröker <broeker.markus@googlemail.com>
Fri, 13 Nov 2015 18:09:56 +0100
changeset 16 f09eccb386ca
parent 15 560d53f840fa
child 17 e7d8b7d8852a
Datenbank ist jetzt frei konfigurierbar
classes/bfw/Configuration.php
classes/bfw/database/Database.php
--- 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);
     }
 
     /**