summaryrefslogtreecommitdiff
path: root/web/lib/DB.class.php
blob: 09759892f26ca7bf7deefccf34ae9a9aaf1574ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;
	}
}