forked from kylemcdonald/socialroulette.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.php
76 lines (50 loc) · 1.59 KB
/
db.php
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
class DB {
private static $pdo;
public static function query ($stmt, $fetchMode = '') {
try {
return self::$pdo->query($stmt, $fetchMode);
} catch(PDOException $e) {
// echo $e->getMessage();
}
}
public static function exec ($stmt) {
try {
return self::$pdo->exec($stmt);
} catch(PDOException $e) {
// echo $e->getMessage();
}
}
public static function lastInsertId () {
try {
return self::$pdo->lastInsertId();
} catch(PDOException $e) {
// echo $e->getMessage();
}
}
public static function prepare ($stmt) {
try {
return self::$pdo->prepare($stmt);
} catch(PDOException $e) {
// echo $e->getMessage();
}
}
private function __construct() {}
public static function connect() {
$options = array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
try {
self::$pdo = new PDO("mysql:host=".Config::db_host.";dbname=".Config::db_name, Config::db_user, Config::db_pass, $options);
/*** echo a message saying we have connected ***/
} catch(PDOException $e) {
//echo $e->getMessage();
}
}
// Prevent users to clone the instance
public function __clone() {
trigger_error('Clone is not allowed.', E_USER_ERROR);
}
}
DB::connect();