summaryrefslogtreecommitdiffstats
path: root/web/lib/DB.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'web/lib/DB.class.php')
-rw-r--r--web/lib/DB.class.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/web/lib/DB.class.php b/web/lib/DB.class.php
new file mode 100644
index 0000000..0975989
--- /dev/null
+++ b/web/lib/DB.class.php
@@ -0,0 +1,28 @@
+<?php
+
+class DB {
+
+ /**
+ * A database object
+ */
+ private static $dbh = null;
+
+ /**
+ * Return an already existing database object or newly instantiated object
+ *
+ * @return \PDO A database connection using PDO
+ */
+ public static function connect() {
+ if (self::$dbh === null) {
+ try {
+ self::$dbh = new PDO(AUR_db_DSN_prefix . ":" . AUR_db_host
+ . ";dbname=" . AUR_db_name, AUR_db_user, AUR_db_pass);
+ self::$dbh->exec("SET NAMES 'utf8' COLLATE 'utf8_general_ci';");
+ } catch (PDOException $e) {
+ die('Error - Could not connect to AUR database');
+ }
+ }
+
+ return self::$dbh;
+ }
+}