/**
  * Born:  12-17-2015
  * Author: Shannon C
  * @return \PDO
  * @throws \Exception
  */
 protected static function db()
 {
     if (is_null(static::$db_connection)) {
         static::$db_connection = DB::getInstance();
     }
     return static::$db_connection;
 }
Пример #2
0
 /**
  * Class initialisation
  */
 public static function _init()
 {
     // just checkin', do we have Opauth installed?
     if (!class_exists('Opauth')) {
         throw new \OpauthException('Opauth composer package not installed. Add "opauth/opauth" to composer.json and run a composer update.');
     }
     // load the auth and opauth config
     \Config::load('auth', true);
     \Config::load('opauth', true);
     // determine the auth driver we're going to use
     $drivers = \Config::get('auth.driver', array());
     is_array($drivers) or $drivers = array($drivers);
     if (in_array('Simpleauth', $drivers)) {
         // get the tablename
         \Config::load('simpleauth', true);
         static::$provider_table = \Config::get('simpleauth.table_name', 'users') . '_providers';
         static::$db_connection = \Config::get('simpleauth.db_connection', null);
     } elseif (in_array('Ormauth', $drivers)) {
         // get the tablename
         \Config::load('ormauth', true);
         static::$provider_table = \Config::get('ormauth.table_name', 'users') . '_providers';
         static::$db_connection = \Config::get('ormauth.db_connection', null);
     } else {
         throw new \OpauthException('No supported driver found. Opauth currently only supports Simpleauth and Ormauth.');
     }
 }
Пример #3
0
 protected static function db_connect()
 {
     if (isset(static::$db_connection)) {
         return;
     }
     try {
         $class = get_called_class();
         static::$db_connection = new PDO($class::$DSN_prefix . ':host=' . DB_SERVER . ';dbname=' . DB_DATABASE, DB_USER, DB_PASSWORD);
         static::$db_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $e) {
         throw new FuzzyRecordException("DB connection failed:" . $e->getMessage());
     }
     try {
         static::query($class::$charset_sql);
     } catch (PDOException $e) {
         throw new FuzzyRecordException("Error setting charset to UTF8: " . $e->getMessage());
     }
 }