Location: PHPKode > scripts > KubeStats > install/upgrade_0.1.php
<?php
require_once('../includes/config.php');

function install_error($error)
{
	if(!isset($_GET['ignore_errors']))
	{
		exit($error);
	}
}

$install_version = '0.3';

// Check to see if the script is already installed
if(isset($config['installed']))
{
	if($config['version'] == $install_version)
	{
		// Exit the script
		exit('KubeStats is already installed.');
	}
}

if(!isset($_GET['install']))
{
	echo 'Before you run an upgrade it is recomended that you backup your KubeStats database<br><Br>Are you sure you want to upgrade your KubeStats installation from '.$config['version'].' to '.$install_version.'?<br><br><a href="upgrade_0.1.php?install=1">Yes do it</a>';
}
else
{
	ignore_user_abort(1);

	echo '<pre>';

	// Try to connect to the databse
	echo "Connecting to database.... \t";
    $db_connection = @mysql_connect ($config['db']['host'], $config['db']['user'], $config['db']['pass']) OR install_error('ERROR ('.mysql_error().')');
    $db_select = @mysql_select_db ($config['db']['name']) OR install_error('ERROR ('.mysql_error().')');
	echo "success<br>";
	
	mysql_query("CREATE TABLE `".addslashes($config['db']['pre'])."browsers` (  `browser_id` mediumint(8) unsigned NOT NULL default '0', `site_id` int(11) unsigned NOT NULL default '0',  `count` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`browser_id`,`site_id`))");
	
	// Check that config file is writtable
	echo "Checking config file.. \t\t";
	if(@is_writable('../includes/config.php'))
	{
		echo "success<br>";
	}
	else
	{
		echo 'ERROR (config.php permisions not set correctly)';
		exit;
	}
		
	// Start updating the config file with new variables
	echo "Writting config.php updates.. \t";
	$content = "<?php\n";
	$content.= "\$config['db']['host'] = '".addslashes(stripslashes($config['db']['host']))."';\n";
	$content.= "\$config['db']['name'] = '".addslashes(stripslashes($config['db']['name']))."';\n";
	$content.= "\$config['db']['user'] = '".addslashes(stripslashes($config['db']['user']))."';\n";
	$content.= "\$config['db']['pass'] = '".addslashes(stripslashes($config['db']['pass']))."';\n";
	$content.= "\$config['db']['pre'] = '".addslashes(stripslashes($config['db']['pre']))."';\n";
	$content.= "\n";
	$content.= "\$config['demo'] = '".addslashes(stripslashes($config['demo']))."';\n";
	$content.= "\$config['site_url'] = '".addslashes(stripslashes($config['site_title']))."';\n";
	$content.= "\$config['version'] = '0.3';\n";
	$content.= "\$config['installed'] = '1';\n";
	$content.= "?>";
	
	// Open the includes/config.php for writting
	$handle = fopen('../includes/config.php', 'w');
	// Write the config file
	fwrite($handle, $content);
	// Close the file
	fclose($handle);
	echo "success<br>";
	
	echo "<br><Br><Br>Thank You! for upgrading KubeStats, Please <a href=\"../control/\">click here</a> to access your control panel";

	echo '</pre>';
}
?>
Return current item: KubeStats