123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- class Database
- {
- public $connection = null;
- public static $instance = null;
- private function __construct()
- {
- $this->connect();
- }
-
- public static function instance()
- {
- if (self::$instance === null) {
- self::$instance = new self();
- }
- return self::$instance->connection;
- }
- public function connect()
- {
- try {
- $this->connection = new PDO(BASE_CONNECTION_STRING, BASE_LOGIN, BASE_PASSWORD);
- $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch (Exception $e) {
- echo 'Connection à la base impossible : ', $e->getMessage();
- die();
- }
- }
- }
|