Ejemplo n.º 1
0
 /**
  * (non-PHPdoc).
  *
  * @see Alpha\Model\ActiveRecordProviderInterface::getConnection()
  */
 public static function getConnection()
 {
     $config = ConfigProvider::getInstance();
     if (!isset(self::$connection)) {
         try {
             self::$connection = new SQLite3($config->get('db.file.path'));
         } catch (\Exception $e) {
             self::$logger->fatal('Could not open SQLite database: [' . $e->getMessage() . ']');
         }
     }
     return self::$connection;
 }
Ejemplo n.º 2
0
 /**
  * (non-PHPdoc).
  *
  * @see Alpha\Model\ActiveRecordProviderInterface::getConnection()
  */
 public static function getConnection()
 {
     $config = ConfigProvider::getInstance();
     if (!isset(self::$connection)) {
         try {
             self::$connection = new Mysqli($config->get('db.hostname'), $config->get('db.username'), $config->get('db.password'), $config->get('db.name'));
         } catch (\Exception $e) {
             // if we failed to connect because the database does not exist, create it and try again
             if (strpos($e->getMessage(), 'HY000/1049') !== false) {
                 self::createDatabase();
                 self::$connection = new Mysqli($config->get('db.hostname'), $config->get('db.username'), $config->get('db.password'), $config->get('db.name'));
             }
         }
         self::$connection->set_charset('utf8');
         if (mysqli_connect_error()) {
             self::$logger->fatal('Could not connect to database: [' . mysqli_connect_errno() . '] ' . mysqli_connect_error());
         }
     }
     return self::$connection;
 }