DatabasePDO.class.php 694 Bytes
Newer Older
thibaut-felten's avatar
thibaut-felten committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php

class DatabasePDO extends PDO {

   protected static $singleton = NULL;

   public static function singleton(){
      if(is_null(static::$singleton))
         static::$singleton = new static();

      return static::$singleton;
   }

   public function __construct() {
       // $db = new PDO("sqlite::memory");

       $connectionString = "mysql:host=". DB_HOST;

       if(defined('DB_PORT'))
           $connectionString .= ";port=". DB_PORT;

thibaut-felten's avatar
thibaut-felten committed
22
       $connectionString .= ";dbname=" . DB_DBNAME;
thibaut-felten's avatar
thibaut-felten committed
23 24
       $connectionString .= ";charset=utf8";

thibaut-felten's avatar
thibaut-felten committed
25
      parent::__construct($connectionString,DB_USER,DB_PASSWORD);
thibaut-felten's avatar
thibaut-felten committed
26 27 28
      $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   }
}