/** * Create and return the instance of Illuminate\Database\Capsule\Manager * * @return object the instance of the Capsule if database enabled * in the configuration file (config/database.php), null * if disabled * * @static * @access public * @since Method available since Release 0.1.0 */ public static function connect() { if (self::$config === null) { self::$config = Config::get('database'); } if (self::$config['enabled'] === true) { $capsule = new Capsule(); $capsule->addConnection(self::$config['settings']); $capsule->bootEloquent(); $capsule->setAsGlobal(); self::$capsule = $capsule; return self::$capsule; } else { return null; } }
/** * Return an instance of the database as a \PDO Object instance * * @return Current database instance (\PDO) */ public static function getInstance() { // If the current database and the current config are null if (is_null(self::$db) && is_null(self::$config)) { // Getting the database config from the config file self::$config = Config::get('database'); // Trying to create a \PDO object from the configuration try { $db = new \PDO('mysql:dbname=' . self::$config['database'] . ';host=' . self::$config['host'] . '', self::$config['username'], self::$config['password']); } catch (PDOException $e) { // If it failed, printing the error message echo $e->getMessage(); } // Setting the current database self::$db = $db; } // Returning the current database return self::$db; }