-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.php
executable file
·56 lines (50 loc) · 1.49 KB
/
config.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
50
51
52
53
54
55
56
<?php
class config
{
private static $pdo = null;
public static function getConnexion()
{
if (!isset(self::$pdo)) {
try {
self::$pdo = new PDO(
'mysql:host=localhost;dbname=espritlocation',
'root',
'',
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
]
);
} catch (Exception $e) {
die('Erreur: ' . $e->getMessage());
}
}
return self::$pdo;
}
private $host = 'localhost';
private $username = 'root';
private $password = '';
private $database = 'espritlocation';
public $db;
public function __construct($host = null, $username = null, $password = null, $database = null)
{
if ($host != null) {
$this->host = $host;
$this->username = $username;
$this->password = $password;
$this->datebase = $database;
}
$this->db = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->database, $this->username, $this->password, array
(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'
)
);
}
public function query($sql, $data = array())
{
$req = $this->db->prepare($sql);
$req->execute($data);
return $req->fetchAll(PDO::FETCH_OBJ);
}
}
?>