Created
September 12, 2012 23:44
-
-
Save danramosd/3710816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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