<?php
/*~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!
!		!!! Разработка сайтов и отдельных модулей на PHP !!!
!	* - Автор скрипата   :  lugaro
!	* - E-mail           :  lugaro@bk.ru
!	* - Сайт             :  wapNEW.ru
!	* - ICQ              :  2000882
~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!*/
class db{
	public $error;
	public $count_sql;
	public $db;
    /*
    * $host - Хост
    * $user - Юзер
    * $pas  - Пароль
    * $base - База
    */
	function __construct($host = '', $user = '', $pas = '', $base = ''){
		if($host != ''){
			$this->db = mysql_connect($host, $user, $pas) or die('Ошибка соединения с базой');
	    	mysql_select_db($base, $this->db) or die('Ошибка выбора базы');
			$this->query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'");
		}else{
			$this->db = false;
		}
	}
    public function query($sql)
    {
    	$this->count_sql++;
        return $this->db ? mysql_query($sql, $this->db) : mysql_query($sql);
    }
    public function result($sql)
    {
        return mysql_result($sql, 0);
    }
    public function assoc($sql)
    {
        return mysql_fetch_assoc($sql);
    }
    public function rows($sql)
    {
        return mysql_num_rows($sql);
    }
    public function row($sql)
    {
        return mysql_fetch_row($sql);
    }
    public function insert_id()
    {
        return $this->db ? mysql_insert_id($this->db) : mysql_insert_id();
        return mysql_insert_id($this->db);
    }
    public function escape($msg)
    {
        return mysql_escape_string($msg);
    }

    public function __destruct()
    {
    	if($this->db) mysql_close($this->db);
    }
}
?>