-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdatabase.php
More file actions
39 lines (31 loc) · 907 Bytes
/
database.php
File metadata and controls
39 lines (31 loc) · 907 Bytes
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
<?php
class Database{
private static $dbName = 'buoy';
private static $dbHost = 'localhost';
private static $dbUsername = 'yii2buoy';
private static $dbPassword = 'pw';
private static $cont = null;
public function __construct(){
die('Init function not allowed. Use connect instead');
}
public static function connect(){
if(null == self::$cont){
try {
self::$cont = new PDO(
"mysql:host=".self::$dbHost.";"."dbname=".self::$dbName.";",
self::$dbUsername,
self::$dbPassword);
self::$cont->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
self::$cont->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e){
die($e->getMessage());
}
}
return self::$cont;
}
public static function disconnect() {
self::$cont = null;
}
}
?>