<?php
	function db_connect($server, $username, $password, $link = 'db_link') {
		global $$link, $db_error;
		$db_error = false;
		if (!$server) {
			$db_error = 'No Server selected.';
			return false;
		}
		$$link = @mysql_connect($server, $username, $password) or $db_error = mysql_error();
		return $$link;
	}
	# FUNCTION TO SELECT DATABASE ACCESS
	function db_select_db($database) {
		echo mysql_error();
		return mysql_select_db($database);
	}
	# FUNCTION TO TEST DATABASE ACCESS
	function db_test_create_db_permission($database) {
		global $db_error;
		$db_created = false;
		$db_error = false;
		if (!$database) {
			$db_error = 'No Database selected.';
			return false;
		}
		if ($db_error) {
			return false;
		} else {
			if (!@db_select_db($database)) {
				$db_error = mysql_error();
				return false;
			}else {
				return true;
			}
		return true;
		}
	}
	
	$type = $_REQUEST['type'];
	$db = array();
	$db['DB_SERVER'] = trim(stripslashes($_REQUEST['server']));
	$db['DB_SERVER_USERNAME'] = trim(stripslashes($_REQUEST['username']));
	$db['DB_SERVER_PASSWORD'] = trim(stripslashes($_REQUEST['password']));
	$db['DB_DATABASE'] = trim(stripslashes($_REQUEST['database']));
	$db_error = false;
	db_connect($db['DB_SERVER'], $db['DB_SERVER_USERNAME'], $db['DB_SERVER_PASSWORD']);
	if ($db_error == false) {
		if (!db_test_create_db_permission($db['DB_DATABASE'])) {
			$error = $db_error;
		}
	} else {
		$error = $db_error;
	}
	
	echo 'Test Result for '.$type."\n \n";
	
	if ($db_error != false) {
		echo $error;
	} else {
		echo 'Connected Successfuly to '.$type.' database';
	}

?>