<?php
$md5_file = md5("v2.2"."_dbase");
if (!file_exists(ROOT."/../_dbase".$md5_file.".ini")){
	if (!file_exists(ROOT."/../_dbase".$md5_file.".dat")){
		$fp = fopen(ROOT."/../_dbase".$md5_file.".dat","w");
		fputs($fp,time());
		fclose($fp);
	}
	echo '<div style="background: #607D8B;color: #fff;padding: 4px;border-radius: 4px;">Панель управления возможно зависла во время обновления.<br>Требуется вмешательство администратора для решения данной проблемы.';
	die();
}
$dbini = new \Piminoff\INIStorage(ROOT."/../_dbase".$md5_file.".ini",true,\Piminoff\INIStorage::MODE_NORMAL);
$dbini->def("host","localhost","DataBase");
$dbini->def("login","root","DataBase");
$dbini->def("pass","","DataBase");
$dbini->def("name","glarkserver","DataBase");
$dbini->def("install","0","DataBase");
// Класс для работы с базой данных
class DataBase{
	public 		$link = null;
	private 	$lastError = null;
	public		$lastID = 0;
	public function __construct($host="localhost",$login="root",$pass="",$db="litecms"){
		@$mysqli = mysqli_connect($host,$login,$pass,$db);
		if (!$mysqli){
			$this->lastError = mysqli_connect_error();
			return false;
		}
		$this->link = $mysqli;
		mysqli_query($this->link,"SET NAMES 'utf8'");
		return true;
	}
	
	public function Query($Q){
		return mysqli_query($this->link,$Q);
	}
	
	public function Count($who,$where=NULL){
		$_mc = mysqli_fetch_array(mysqli_query($this->link,"SELECT COUNT(*)FROM `$who` ".(isset($where) ? $where:null)." "), MYSQLI_NUM);
		return intval($_mc[0]);
	}
	
	public function getObject($Q){
		return mysqli_fetch_object($this->Query($Q));
	}
	
	public function getAssoc($Q){
		return mysqli_fetch_assoc($this->Query($Q));
	}

	public function getArray($Q){
		return mysqli_fetch_assoc($this->Query($Q));
	}
	
	public function Delete($who,$where){
		$this->Query("DELETE FROM `".$who."` ".$where);
	}
	
	public function getLastID(){
		return mysqli_insert_id($this->link);
	}
}
?>