diff options
Diffstat (limited to 'php/ConnectionDatabase.php')
-rw-r--r-- | php/ConnectionDatabase.php | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/php/ConnectionDatabase.php b/php/ConnectionDatabase.php deleted file mode 100644 index b26d0bd..0000000 --- a/php/ConnectionDatabase.php +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | <?php | ||
2 | // php/ConnectionDatabase.php | ||
3 | |||
4 | class 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 | } | ||