summaryrefslogtreecommitdiff
path: root/php/Connection.php
diff options
context:
space:
mode:
Diffstat (limited to 'php/Connection.php')
-rw-r--r--php/Connection.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/php/Connection.php b/php/Connection.php
new file mode 100644
index 0000000..bdc7aa9
--- /dev/null
+++ b/php/Connection.php
@@ -0,0 +1,35 @@
1<?php
2// php/Connection.php
3
4class Connection extends PDO
5{
6 // paramètres du constructeur de PDO, avec sqlite seul le premier est nécessaire
7 public static $dsn = ''; // Data Source Name = 1er paramètre
8 public static $user = '';
9 public static $password = '';
10 public static $options = '';
11 private static $Instance;
12
13 public function __construct()
14 {
15 try
16 {
17 parent::__construct(self::$dsn); // renseigne la variable $dsn de la classe PDO
18 $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // $this pour la méthode du parent PDO
19 }
20 catch(PDOException $e)
21 {
22 die('Erreur : '.$e->getMessage());
23 }
24 }
25
26 // créer son objet avec: $bdd = Connection::getInstance();
27 public static function getInstance(): self
28 {
29 if(self::$Instance === null)
30 {
31 self::$Instance = new self();
32 }
33 return self::$Instance;
34 }
35}