Location: PHPKode > projects > HypatiaDB > hypatiadb/install.php
<?php
include("common_db.php");
include("functions.php");
headers();
html();
head("Installation");

echo ('<body>');

if(isset($_REQUEST['doinstall'])) {
	//hokay. install!
	//TODO: l10n
	$dbhostname = $_REQUEST['dbhostname'];
	$dbusername = $_REQUEST['dbusername'];
	$dbpassword = $_REQUEST['dbpassword'];

	$database = mysql_connect($dbhostname, $dbusername, $dbpassword);
	if($database) {

		//create the database username and password file
		file_put_contents('database-password.php', '<?php $host = \'' . $dbhostname . '\'; $username = \'' . $dbusername . '\'; $password = \'' . $dbpassword . '\'; ?>');

		if($_REQUEST['adminpassword'] != $_REQUEST['adminpwdc']) {
			echo('<p class="error">Your password and its confirmation did not match.</p>');
		} else {
		$mysql = "mysql -h $dbhostname -u $dbusername ";
		if($dbpassword != '')
			$mysql .= " -p$dbpassword ";
		$command = "$mysql < sql/schema.sql";
		echo('<pre>' . passthru($command) . '</pre>');

		$mysql .= ' HypatiaDB';

		$command = "$mysql < languages/" . $_REQUEST['language'] . '.sql';
		echo('<pre>' . passthru($command) . '</pre>');

		mysql_select_db('HypatiaDB', $database);
			$username = mysql_real_escape_string($_REQUEST['adminusername']);
			$password = mysql_real_escape_string($_REQUEST['adminpassword']);
			$email = mysql_real_escape_string($_REQUEST['adminemail']);
		$query = "INSERT INTO users(username, password, email, status) VALUES ('$username', '$password', '$email', 'admin')";
		if(!mysql_query($query)) {
			echo('<p class="error">Unable to create the administrative user: ' . mysql_error() . '</p>');
		} else {
			echo('<p>Congratulations! You have successfully installed HypatiaDB. You may wish to delete the file "install.php" in the HypatiaDB directory.</p><p><a href="index.php">Log in to HypatiaDB</a>.</p>');
		}
	}} else {
		echo('<p class=\"error\">Unable to connect to the database: ' . mysql_error() . '</p>');
	}
?>

<?php
} else {
?>
		<p>Welcome to HypatiaDB, the easiest way to manage your business and personal data. If you currently use Microsoft Access for managing your data, you can import those data directly into Hypatia. If you haven&#8217;t used Microsoft Access or another database system before, don&#8217;t worry. Hypatia is easy to use and comes with a comprehensive set of documentation.</p>
		<p>HypatiaDB requires a webserver, such as Apache (version 1.3 or 2.0); and the free MySQL database (version 4.1 or above).</p>
		<form action="install.php" method="POST" class="standalone lblock">
			<p><label for="dbhostname">Database Hostname: <input type="text" name="dbhostname" value="localhost" /></label>
				The computer which hosts your database. Generally <q>localhost</q>.</p>
			<p><label for="dbusername">Database Username: <input type="text" name="dbusername" /></label>
				The username that HypatiaDB should use to access the database. This user will need to have access to all the tables that you want to control with HypatiaDB, and should have the ability to create databases.</p>
			<p><label for="dbpassword">Database Password: <input type="password" name="dbpassword" /></label>
				The password for the database user specified above.</p>
			<hr />
			<p><label for="adminusername">Administrator Username: <input type="text" name="adminusername" /></label>
				This user is the HypatiaDB administrator, and will be able to create further users.</p>
			<p><label for="adminpassword">Administrator Password: <input type="password" name="adminpassword" /></label>
				The password for the administrator.</p>
			<p><label for="adminpwdc">Confirm Password: <input type="password" name="adminpwdc" /></label>
				Please retype the above password for confirmation.</p>
			<p><label for="adminemail">Administrator Email: <input type="text" name="adminemail" /></label>
				This is the email to which your password will be sent, should you forget it. If you do not enter an email address here, you will be unable to recover your password.</p>
			<p><label for="language">Language: <select name="language">
				<option value="en-au">English (Australian)</option>
				<option value="en-au">English (Commonwealth)</option>
			</select></label>Please select the desired language.</p>
			<input type="submit" value="Install" name="doinstall" />
		</form>
<?php
}
endhtml();
?>
Return current item: HypatiaDB