public static function apply_delta_file(Database_DeltaFile $delta_file) { $root_dbh = Database_ConnectionsHelper::get_root_connection_using_cli(); mysql_query($delta_file->get_contents(), $root_dbh); #self::record_delta_file_application($delta_file); $delta_file->record_application(); }
public static function get_root_connection_using_cli($root_username = NULL) { if (!isset(self::$root_password)) { fwrite(STDERR, 'Please enter the root password: ' . PHP_EOL); self::$root_password = trim(fgets(STDIN)); } return self::get_root_connection(self::$root_password, $root_username); }
public static function tear_down() { $dbh = Database_ConnectionsHelper::get_root_connection_using_cli(); $stmt = <<<SQL DROP TABLE hc_database_test_1; SQL; mysql_query($stmt, $dbh); }
public static function m() { #$mysql_user_factory = Database_MySQLUserFactory::get_instance(); #$mysql_user = $mysql_user_factory->get_for_this_project(); #$database = $mysql_user->get_database(); # #$dbh = $database->get_database_handle(); # #return $dbh; return Database_ConnectionsHelper::get_database_handle(); }
public static function tear_down() { $dbh = Database_ConnectionsHelper::get_root_connection_using_cli(); $stmt = <<<SQL DROP TABLE hc_database_test_1; DROP TABLE hc_database_test_2; DROP TABLE hc_database_test_3; SQL; mysql_query($stmt, $dbh); FileSystem_DirectoryHelper::delete_recursively(self::get_table_specification_directory_name()); }
public static function test_database_is_selectable() { return Database_ConnectionsHelper::is_database_selectable(); }
public function do_actions() { $root_dbh = Database_ConnectionsHelper::get_root_connection_using_cli(); Database_DatabaseHelper::reset_database($root_dbh); }
/** * This function makes the database * like the table specification. */ public static function sync_table_specification_with_database($root_password) { $specified_tables = self::get_tables(); #print_r($specified_tables); foreach ($specified_tables as $specified_table) { #$table_name = $specified_table->get_name(); #echo '$table_name: ' . $table_name . PHP_EOL; /* * Does the table exist? * * If not, create it. */ $dbh = Database_ConnectionsHelper::get_root_connection($root_password); #$query = "SHOW TABLES LIKE $table_name"; # #$result = mysql_query($query, $dbh); # #if (mysql_num_rows($result) == 0) { # $stmt = #} #$stmt = "CREATE TABLE IF NOT EXISTS $table_name"; $create_statement = $specified_table->get_create_statement(); echo '$create_statement: ' . $create_statement . PHP_EOL; #mysql_query($stmt, $dbh); } }
public function do_actions() { if (Database_ConnectionsHelper::is_database_selectable()) { fwrite(STDERR, 'MySQL User and Database are already online, exiting.' . PHP_EOL); } else { $passwords_file = Database_PasswordsFileHelper::get_passwords_file(); /* * Get the root password for the mysql server */ printf('Please enter the root password for \'%s\'' . PHP_EOL, $passwords_file->get_host()); $root_password = trim(fgets(STDIN)); $root_dbh = mysql_connect($passwords_file->get_host(), 'root', $root_password); /* * Don't use this function - the * database hasn't been created yet! */ #$root_dbh # = Database_ConnectionsHelper # ::get_root_connection_using_cli(); $username = $passwords_file->get_username(); $password = $passwords_file->get_password(); $database = $passwords_file->get_database(); /* * Shouldn't this be settable? */ $accessing_host = 'localhost'; /* * Create the user. */ mysql_query(<<<SQL CREATE USER '{$username}'@'{$accessing_host}' IDENTIFIED BY '{$password}' SQL , $root_dbh); /* * Create the database. */ mysql_query(<<<SQL CREATE DATABASE {$database} SQL , $root_dbh); /* * Grant a minimal set of permissions on the database for the user. */ mysql_query(<<<SQL GRANT SELECT, INSERT, UPDATE, DELETE ON {$database}.* TO '{$username}'@'{$accessing_host}' SQL , $root_dbh); } }