forked from ceal1818/web-sample-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.php
37 lines (33 loc) · 863 Bytes
/
database.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
<?php
class Database
{
private static $dbName = 'app' ;
private static $dbHost = '192.168.1.145' ;
private static $dbUsername = 'appuser';
private static $dbUserPassword = '1234';
private static $cont = null;
public function __construct() {
die('Init function is not allowed');
}
public static function connect()
{
// One connection through whole application
if ( null == self::$cont )
{
try
{
self::$cont = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
}
catch(PDOException $e)
{
die($e->getMessage());
}
}
return self::$cont;
}
public static function disconnect()
{
self::$cont = null;
}
}
?>