/
DatabaseConfig.php
49 lines (44 loc) · 1.08 KB
/
DatabaseConfig.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
<?php
/**
* Class for DatabaseConfig
* @author gkannaiy
*
*/
class DatabaseConfig
{
private static $dbHost = 'localhost' ;
private static $dbUsername = 'root';
private static $dbUserPassword = 'gopi';
private static $dbName = 'foodora-test' ;
private static $cont = null;
/**
* Constrcut method
*/
public function __construct()
{
exit('Init function is not allowed');
}
/**
* PDO database connection starts
* return database connection instance
*/
public 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;
}
/**
* PDO database connection close
*/
public static function disconnect()
{
$this->cont = null;
}
}