<?php
final class sql {
	
	private $server, $user_name, $user_pass, $db_name, $sql_link;
	
	public function __construct()
		{
		$this->server = 'localhost';
		$this->user_name = 'name';
		$this->user_pass = 'pass';
		$this->db_name = 'e_learning';
		$this->sql_link = '';
		
		$this->sql_connect($this->dbName);
	
		if ( $this->sql_link == '' )
			{
			$this->error = true;
			}
		}
	
	public function return_error_text($text)
		{
		echo '<h3 style="color: red;">' . $text . '</h3>';
		}
	
	public function sql_connect($db)
		{
		if ( !empty($db) ) {$this->db_name = $db;}
		$link = mysql_connect($this->server, $this->user_name, $this->user_pass);
		if ( $link )
			{
			$db_link = mysql_select_db($this->db_name, $link);
			if ( $db_link )
				{
				mysql_query("SET NAMES utf8");
				$this->$sql_link = $link;
				}
			else
				{
				$this->return_error_text('Cannot connect to database.');
				}
			}
		else
			{
			$this->return_error_text('Cannot connect to server.');
			}
		}
	
	public function sql_free_result($result)
		{
		if ( !isset($result) || (!$result) )
			{
			return false;
			}
		else
			{
			return mysql_free_result($result);
			return false;
			}
		}
		
	public function sql_close()
		{
		if ( $this->sql_link == '' )
			{
			return true;
			}
		else
			{
			$close_link = mysql_close($this->sql_link);
			if ( $close_link )
				{
				$this->sql_link = '';
				}
			}
		}
}
	
?>