Skip to content

Instantly share code, notes, and snippets.

@mageekguy
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mageekguy/10017715 to your computer and use it in GitHub Desktop.
Save mageekguy/10017715 to your computer and use it in GitHub Desktop.
Using collection to find a table in a database and throwing an exception if the table already exists.
$database
->select(function($innerTable) use ($table) { return $table->getName() === $innerTable->getName(); }, 1, function() use ($table, $database) {
$database->add($table);
$table->setDatabase($database);
}
)
->apply(function($table) use ($database) { throw new database\exception('Table \'' . $table . '\' already exists in \'' . $database . '\''); })
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment