Exemplo n.º 1
0
 /**
  * Remove created databases.
  *
  * @return void
  */
 function __destruct()
 {
     if (empty($this->databases)) {
         return;
     }
     $database = new Database(HELPER_MYSQL_DSN, HELPER_MYSQL_USERNAME, HELPER_MYSQL_PASSWORD);
     foreach ($this->databases as $databaseName) {
         $database->exec('DROP DATABASE ' . $databaseName);
     }
 }
Exemplo n.º 2
0
 /**
  * Create the database.
  *
  * @param  Configuration  $configuration    Configuration.
  * @return Database
  * @throw  Exception\Installation
  */
 static function createDatabase(Configuration $configuration)
 {
     if (!isset($configuration->database)) {
         throw new Exception\Installation('Configuration is corrupted, the database branch is missing.', 8);
     }
     try {
         $database = new Database($configuration->database->dsn, $configuration->database->username, $configuration->database->password);
     } catch (PDOException $exception) {
         throw new Exception\Installation('Cannot create the database.', 9, null, $exception);
     }
     $templateSchemaIterator = $database->getTemplateSchemaIterator();
     try {
         foreach ($templateSchemaIterator as $templateSchema) {
             $schema = $templateSchema->open()->readAll();
             $verdict = $database->exec($schema);
             if (false === $verdict) {
                 throw new PDOException('Unable to execute the following schema:' . "\n" . $schema, 10);
             }
             $templateSchema->close();
         }
     } catch (PDOException $exception) {
         throw new Exception\Installation('An error occured while setting up the database.', 11, null, $exception);
     }
     return $database;
 }