コード例 #1
0
ファイル: Database.php プロジェクト: eruraindil/MattMVC
 /**
  * Static method get
  *
  * @param  array $group
  * @return \helpers\database
  */
 public static function get($group = false)
 {
     // Determining if exists or it's not empty, then use default group defined in config
     if (!$group) {
         $group = array('type' => App::DB_TYPE, 'host' => App::DB_HOST, 'name' => App::DB_NAME, 'user' => App::DB_USER, 'pass' => App::DB_PASS);
         if ($group['type'] == 'sqlite') {
             $group['file'] = App::DB_FILE;
         }
     } else {
         $group = $group;
     }
     // Group information
     $type = $group['type'];
     $host = $group['host'];
     $name = $group['name'];
     $user = $group['user'];
     $pass = $group['pass'];
     if (isset($group['file'])) {
         $file = $group['file'];
     }
     // ID for database based on the group information
     $id = "{$type}.{$host}.{$name}.{$user}.{$pass}";
     // Checking if the same
     if (isset(self::$instances[$id])) {
         return self::$instances[$id];
     }
     try {
         // I've run into problem where
         // SET NAMES "UTF8" not working on some hostings.
         // Specifiying charset in DSN fixes the charset problem perfectly!
         if (isset($file)) {
             $instance = new Database("{$type}:{$file}");
         } else {
             $instance = new Database("{$type}:host={$host};dbname={$name};charset=utf8", $user, $pass);
         }
         $instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         // Setting Database into $instances to avoid duplication
         self::$instances[$id] = $instance;
         return $instance;
     } catch (PDOException $e) {
         //in the event of an error record the error to errorlog.html
         Debug::alert($e);
     }
 }
コード例 #2
0
ファイル: index.php プロジェクト: eruraindil/MattMVC
<?php

if (file_exists('../vendor/autoload.php')) {
    require '../vendor/autoload.php';
} else {
    echo "<h1>Please install via composer.json</h1>";
}
use MattMVC\Core\Debug;
use MattMVC\Core\App;
Debug::register();
define('ENVIRONMENT', 'development');
if (defined('ENVIRONMENT')) {
    switch (ENVIRONMENT) {
        case 'development':
            break;
        case 'production':
            Debug::debug(false);
            //true = show erros; false hide errors
            break;
        default:
            exit('The application environment is not set correctly.');
    }
}
$app = new App();