-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.php
37 lines (29 loc) · 1.04 KB
/
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 $dbHost = "localhost";
private static $dbName = "burger_code";
private static $dbUser = "root";
private static $dbUserPassword = "";
private static $connection = null;
public static function connect()
{
/*Je cree une variable connexion pour la connexion a ma db. Avec gestion des erreurs pour ne pas divulger des details de connexion*/
try
{
self::$connection = new PDO ("mysql:host=" . self::$dbHost . ";dbname=" . self::$dbName,self::$dbUser,self::$dbUserPassword, array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); /* array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION) permet de detecter des erreurs precisement*/
}
catch(PDOException $e)
{
die($e->getMessage());
}
return self::$connection;
}
public static function disconnect()
{
self::$connection = null;
}
}
/* code de la connexion a la database*/
Database::connect();
?>