public static function get_root_connection($root_password, $root_username = NULL) { if (!isset($root_username)) { $root_username = '******'; } $passwords_file = Database_PasswordsFileHelper::get_passwords_file(); $dbh = mysql_connect($passwords_file->get_host(), $root_username, $root_password); if (!$dbh) { throw new Database_UnableToMakeConnectionException($root_username, $passwords_file->get_host()); } if (mysql_select_db($passwords_file->get_database(), $dbh)) { return $dbh; } else { throw new Database_MySQLException($dbh); } }
private function get_passwords_file_for_this_project() { #$project_directory_finder # = HaddockProjectOrganisation_ProjectDirectoryFinder::get_instance(); # #$project_directory # = $project_directory_finder->get_project_directory_for_this_project(); # #//$project_specific_directory #// = $project_directory->get_project_specific_directory(); #// #//$passwords_file = $project_specific_directory->get_passwords_file(); # #$passwords_file = $project_directory->get_passwords_file(); # #return $passwords_file; return Database_PasswordsFileHelper::get_passwords_file(); }
public static function test_passwords_file_exists() { $passwords_file = Database_PasswordsFileHelper::get_passwords_file(); return $passwords_file->exists(); }
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); } }