Location: PHPKode > projects > PHP SQL Server (MSSQL) Query Analyzer > phpqa/Configuration.php
<?php
	include ('common.header.php');

	include ('common.topmenu.php');
	
	include ('common.library.php');
	
	
	if (!empty ($_POST['save']))
	{
		$db_hostname = $_POST['db_hostname'];
		$port = $_POST['port'];
		$db_name = $_POST['db_name'];
		$username = $_POST['username'];
		$password = $_POST['password'];
		
		$data = "<?php\n/*\nPHP Query Analyzer\n\nGenerated by Configuration.php\non ".date('r')."\n*/\n\n\$db_hostname='{$_POST['db_hostname']}';\n\$port={$_POST['port']};\n\$db_name='{$_POST['db_name']}';\n\$username='{$_POST['username']}';\n\$password='{$_POST['password']}';\n\n?>";
		
		$handle = @fopen('db.vars.php', "w+");
		@fwrite($handle, $data);
		@fclose($handle);			
	}
	
	
	include ('db.vars.php');

	echo "<div id='content'>";
	
	echo "
	<div id='secondaryContent'>
	
	<h3>Database Information</h3>
	<form method='post'>
	<ul>
		<li>DB hostname<br><input type='text' name='db_hostname' value='$db_hostname'></li><br>
		<li>Port<br><input type='text' name='port' value='$port'></li><br>
		<li>Username<br><input type='text' name='username' value='$username'></li><br>
		<li>Password<br><input type='password' name='password' value='$password'></li><br>";
		
		echo "<li>DB name<br>";
		
		$_CONEXAO = @mssql_connect ("$db_hostname,$port", $username, $password);
		@mssql_select_db ($db_name, $_CONEXAO);
		
		if ($_CONEXAO)
		{
			echo "<select name='db_name'>";
	
			$query = "sp_databases";
			$resultado = mssql_query($query, $_CONEXAO);
			while ($campo = mssql_fetch_array ($resultado, MSSQL_ASSOC))
			{
				$banco = $campo['DATABASE_NAME'];
			
				echo "<option value='$banco'".((strtolower($banco) == strtolower($db_name)) ? "selected" : "").">$banco</option>";
			}
		
			echo "</select>";
		}
		else
		{
			echo "<input type='text' name='db_name' value='$db_name'>";
		}
		
		echo "</li><br>";
		echo "<div align='center'><input type='submit' value='Save' name='save'></div>
	</ul>
	</form>
	<div class='xbg'></div>
</div>
		";			
	
	echo "<div id='primaryContentContainer'><div id='primaryContent'>";
	echo "<p>";
	
	echo "<h3>Trying to connect on hostname $db_hostname port $port</h3>";
	
	$fp = @fsockopen($db_hostname, $port, $errno, $errstr, 5);
	if (!$fp)
	{
		echo "<blockquote style='color: red; border-left: solid 0.75em #FF0000;'>$errstr ($errno)</blockquote>";
	}
	else
	{
		echo "<blockquote style='color: green'>Connection sucessful at <b>$db_hostname:$port</b></blockquote><br>";
		
		echo "<h3>Testing db connection to string <b>$username:".str_repeat("*", strlen($password))."@$db_hostname:$port</b></h3>";
	
		if ( ! ($_CONEXAO = @mssql_connect ("$db_hostname,$port", $username, $password) ) )
		{
			echo "<blockquote style='color: red; border-left: solid 0.75em #FF0000;'>";
			echo "Error on connection, string=[$username:".str_repeat("*", strlen($password))."->$db_name@$db_hostname:$port]. MSSQL return:<br>"; 
			echo mssql_get_last_message();
			echo "</blockquote>";
		} 
		elseif ( ! ( @mssql_select_db ($db_name, $_CONEXAO) ) )
		{
			echo "<blockquote style='color: red; border-left: solid 0.75em #FF0000;'>";
			echo "Error selecting db <b></b>, string=[$username:".str_repeat("*", strlen($password))."->$db_name@$db_hostname:$port]. MSSQL return:<br>"; 
			echo mssql_get_last_message();
			echo "</blockquote>";
		}	
		else
		{
			echo "<blockquote style='color: green'><span style='font-color: green'>Connection sucessful at <b>$username:$password@$db_hostname:$port</b></span></blockquote><br><br>";
		}		
	}
	
	
	echo "</p>";
	echo "</div></div>";	
	

	
	echo "<div class='clear'></div>";
	
	//closing div id='content'
	echo "</div>";
	
	include ('common.footer.php');
	
	//closing div id=outer
	echo "</div>";
	
	echo "</body></html>";

?>
Return current item: PHP SQL Server (MSSQL) Query Analyzer