-
Notifications
You must be signed in to change notification settings - Fork 15
/
sql.php.dist
36 lines (30 loc) · 941 Bytes
/
sql.php.dist
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
<?php
class Database
{
private static $dbName = 'cognacbox';
private static $dbHost = 'localhost';
private static $dbUsername = 'root';
private static $dbUserPassword = 'root';
private static $cont = null;
public function __construct()
{
die('Init function is not allowed');
}
public static function connect()
{
// Only one connection allowed through whole application
if (null == self::$cont) {
try {
self::$cont = new PDO('mysql:host='.self::$dbHost.';'.'dbname='.self::$dbName, self::$dbUsername, self::$dbUserPassword);
self::$cont->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: '.$e->getMessage();
}
}
return self::$cont;
}
public static function disconnect()
{
self::$cont = null;
}
}