Add database wrapper class and new connection method
[aur.git] / web / lib / DB.class.php
blob09759892f26ca7bf7deefccf34ae9a9aaf1574ae
1 <?php
3 class DB {
5 /**
6 * A database object
7 */
8 private static $dbh = null;
10 /**
11 * Return an already existing database object or newly instantiated object
13 * @return \PDO A database connection using PDO
15 public static function connect() {
16 if (self::$dbh === null) {
17 try {
18 self::$dbh = new PDO(AUR_db_DSN_prefix . ":" . AUR_db_host
19 . ";dbname=" . AUR_db_name, AUR_db_user, AUR_db_pass);
20 self::$dbh->exec("SET NAMES 'utf8' COLLATE 'utf8_general_ci';");
21 } catch (PDOException $e) {
22 die('Error - Could not connect to AUR database');
26 return self::$dbh;