blob: b538e0d3e28b5a07101e10e6c8d393e9e80811a3 (
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
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<?php
include_once("confparser.inc.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 {
$dsn_prefix = config_get('database', 'dsn_prefix');
$host = config_get('database', 'host');
$socket = config_get('database', 'socket');
$name = config_get('database', 'name');
$user = config_get('database', 'user');
$password = config_get('database', 'password');
$dsn = $dsn_prefix .
':host=' . $host .
';unix_socket=' . $socket .
';dbname=' . $name;
self::$dbh = new PDO($dsn, $user, $password);
self::$dbh->exec("SET NAMES 'utf8' COLLATE 'utf8_general_ci';");
} catch (PDOException $e) {
die('Error - Could not connect to AUR database');
}
}
return self::$dbh;
}
}
|