Skip to content

Instantly share code, notes, and snippets.

@danramosd
Created September 12, 2012 23:44
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 danramosd/3710816 to your computer and use it in GitHub Desktop.
Save danramosd/3710816 to your computer and use it in GitHub Desktop.
<?php
abstract class MigrationScaffold{
private static $link;
/**
* Creates the connection to the proper database
*
* @param $env - ['dev' || 'prod' || 'test']
* @return void
*/
public function __construct($env = 'test'){
if( $env == 'dev' ){ self::$link = mysqli_connect('localhost', 'root', 'root', 'development');}
else if( $env == 'test' ){ self::$link = mysqli_connect('localhost', 'root', 'root', 'testing');}
else if( $env == 'prod' ){ self::$link = mysqli_connect('localhost', 'root', 'root', 'production'); }
if ( !self::$link ) {
die( 'We had some trouble connecting to the database : ' . mysqli_error(self::$link) );
}
}//end:__construct();
/**
* This runs the actual migration and takes care of error reporting
*
*/
protected function run($sql){
mysqli_query(self::$link, $sql);
if(mysqli_error(self::$link)){
echo mysqli_error(self::$link);
}
}//end:run()
abstract protected function up();
abstract protected function down();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment