-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.php
40 lines (32 loc) · 964 Bytes
/
base.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
<?php
class base{
private static $connection;
private static $host = "localhost";
private static $user = "projet_csi";
private static $pass = "csi";
private static $base = "projet_csi";
/* Permet d'obtenir une connection à la base
* (Les paramètres de connections sont stockés dans le fichier paramco.php)
* Il faut créer une connection PDO distante
*/
public static function getConnection(){
if (isset(self::$connection)) {
return self::$connection;
}else{
self::$connection = self::connect();
return self::$connection;
}
}
public static function connect(){
try{
$dns = "mysql:host=" . self::$host . ";dbname=" . self::$base . ";";
$connection = new PDO($dns, self::$user, self::$pass,
array(PDO::ERRMODE_EXCEPTION=>true, PDO::ATTR_PERSISTENT=>true));
$connection->exec("SET CHARACTER SET utf8");
return($connection);
}catch (Exception $e){
die('Erreur : ' . $e->getMessage());
}
}
}
?>