Location: PHPKode > scripts > Some Chess > some-chess/install.php
<?PHP
//		Some Chess, a PHP multi-player chess server.
//		Copyright (C) 2006 Jon Link
function installCheck(){
	$query 		= 'SELECT 1 FROM players LIMIT 0';
	$result 	= mysql_query($query);
	if($result) return true;
	return false;
}
function updateCheck(){
	$query 		= 'SELECT optionValue FROM options WHERE id="0" LIMIT 1';
	$result 	= @mysql_query($query);
	$curVer		= @mysql_result($result,0,'optionValue');
	if($curVer == '') $curVer = '2.0a9';
	if(ver2num($curVer) >= ver2num(shortVer)) return true;
	return false;
}
function ver2num($ver){
	if(strpos($ver,'a')){
		$ver	= preg_replace('/[a-z]*/','',$ver);
		$ver	= $ver + 10;
	}elseif(strpos($ver,'b')){
		$ver	= preg_replace('/[a-z]*/','',$ver);
		$ver	= $ver + 20;	
	}elseif(strpos($ver,'rc')){
		$ver	= preg_replace('/[a-z]*/','',$ver);
		$ver 	= $ver + 30;	
	}else{
		$ver	= $ver + 40;	
	}
	$nums 		= explode('.',$ver);
	$ver		= $nums[0] + $nums[1];
	return $ver;
}
function install($database,$indexStr){
	$instlFile		= 'MYSQL';
	$databaseQuery	= 'CREATE DATABASE IF NOT EXISTS '.$database;
	mysql_query($databaseQuery)or die('<div class="error>'.$indexStr[0].' (in1)</div>');	
	$tableSQL	 	= file_get_contents($instlFile);
	$tableSQL		= explode(';',$tableSQL);
	$SQLCount		= count($tableSQL);
	for($i=0;$i<$SQLCount;++$i){
		if($tableSQL[$i] !=='') $install = mysql_query($tableSQL[$i])or die('<div class="error>'.$indexStr[1].' (in-2.'.$i.')</div>');
	}
	if($install) return $indexStr[2];
	return false;
}
function update($indexStr){
	$updtFile		= 'MYSQL_UPDATE';
	$tableSQL	 	= file_get_contents($updtFile);
	$tableSQL		= explode(';',$tableSQL);
	$SQLCount		= count($tableSQL);
	for($i=0;$i<$SQLCount;++$i){
		if(strpos($tableSQL[$i], shortVer) !== false) $update = true;
		if($update){
			if(strpos($tableSQL[$i],'--') === false && $tableSQL[$i] !=='') $updated = mysql_query($tableSQL[$i])or die('<div class="error>'.$indexStr[3].' (up-'.$i.')</div>');
		}
	}
	if($updated) return $indexStr[4];
	return false;
}
?>
Return current item: Some Chess