summaryrefslogtreecommitdiff
path: root/intern/api/db.php
diff options
context:
space:
mode:
Diffstat (limited to 'intern/api/db.php')
-rw-r--r--intern/api/db.php29
1 files changed, 23 insertions, 6 deletions
diff --git a/intern/api/db.php b/intern/api/db.php
index 9521148..8385ed5 100644
--- a/intern/api/db.php
+++ b/intern/api/db.php
@@ -1,8 +1,25 @@
<?php
-require_once __DIR__ . '/config.php';
-$db = new pdo($dsn, $db_user, $db_passwd);
-$db->exec('SET CHARACTER SET utf8');
+function get_db() {
+ require_once __DIR__ . '/config.php';
+ require_once __DIR__ . '/secrets.php'; // beinhaltet die Parameter für die Datenbank
+
+ try {
+ $db = new pdo($dsn, $db_user, $db_passwd);
+ } catch (Exception $e) {
+ error_log($e->getMessage());
+
+ unset($dsn);
+ unset($db_user);
+ unset($db_passwd);
+
+ return false;
+ }
+ $db->exec('SET CHARACTER SET utf8');
+
+ unset($dsn);
+ unset($db_user);
+ unset($db_passwd);
+
+ return $db;
+}
-unset($dsn);
-unset($db_user);
-unset($db_passwd);