Exemple #1
0
 private function __construct()
 {
     $host = DB_HOST;
     $username = DB_USER;
     $password = DB_PASSWORD;
     $dbname = DB_NAME;
     $db = new \mysqli($host, $username, $password, $dbname);
     self::$db = $db;
 }
Exemple #2
0
 public static function getInstance()
 {
     if (!self::$instance) {
         try {
             $DBHost = Config::HOST;
             $DBName = Config::DATABASE;
             $DBUsername = Config::USER;
             $DBPassword = Config::PASSWORD;
             if ($DBHost === null || $DBName === null || $DBUsername === null || $DBPassword === null) {
                 die('Database: one or more configuration variables are not set ($DBHost, $DBName, $DBUsername, $DBPassword)');
             }
             self::$instance = new PDO("mysql:host={$DBHost};dbname={$DBName}", $DBUsername, $DBPassword);
             $st = self::$instance->prepare("SET NAMES 'utf8'");
             $st->execute();
         } catch (PDOException $e) {
             die($e->getMessage());
         }
     }
     return self::$instance;
 }
Exemple #3
0
 /**
  * Rollback changes.
  */
 public static function rollback()
 {
     // Restore whatever value it was when transaction ends.
     if (isset(self::$transactionStore['autocommit'])) {
         static::query('SET autocommit = ?', self::$transactionStore['autocommit']);
     }
     self::$transactionStore = [];
     return static::getConnection()->rollBack();
 }