<?php


$argv = $_SERVER["argv"];

// install_mysql.php databasename username password

if (count($argv) > 1)
{
	$DatabaseName = $argv[1];

	$HostName = "127.0.0.1";
	$PortNumber = 23306;

	if (count($argv) >= 4)
	{
		$UserName = $argv[2];
		$Password = $argv[3];
	}
	else
	{
		echo( "enter database credentials\n\nuser name: ");
		$UserName = trim(fgets(STDIN));
		if ($UserName === false)
		{
			return;
		}

		system("stty -echo");

		echo("password: ");
		$Password = trim(fgets(STDIN));
		if ($Password === false)
		{
			return;
		}
		
		system("stty echo");
	}

	echo("uninstalling mocha from `" . $DatabaseName . "` with user `" . $UserName . "` and password\n");
	$pdo = new \PDO("mysql:host=" . $HostName . ";port=" . $PortNumber . ";dbname=" . $DatabaseName, $UserName, $Password);

	$query = "DROP DATABASE :database_name";
	$stmt = $pdo->prepare($query);
	$stmt->execute(array("database_name" => $DatabaseName));

	echo("\n\n");
}
?>