<?

class dbMini{

    var $link;

    function dbMini(){
        if (empty($this->link)){
            include "config/config.inc.php";
            $this->link = @mysql_connect($host , $user , $pass );
            mysql_select_db($database, $this->link );
        }
    }
    
    function get($sql, $offset="", $limit=""){
        //print $sql."<br/>";
		
		$result =  mysql_query( $sql, $this->link );

		$numrows=@mysql_num_rows( $result);
		for ($i=0; $i<$numrows; $i++)
            $row[$i]=mysql_fetch_assoc($result);

        return $row;
    }

    function set($sql){
        //echo $sql."<br/>";
		
        mysql_query( $sql, $this->link );
    }
    

	function getLinha($table, $id){
        $sql="select * from $table where id='$id'";

        $linha=$this->get($sql);
        return $linha[0];
		
	}
	
	function getLinhaCampo($table, $campo, $valor){
        $sql="select * from $table where $campo='$valor'";
       // print $sql;
        $linha=$this->get($sql);
        return $linha[0];
	}
	
	function getLista($table, $idCat="", $campos="", $campo="ordem", $ordem=1, $offset=0, $limit=50){
		$camposSql=($campos == '*')?$campos:implode(',',$campos);
        $sql="select $camposSql from $table ";
        if ($idCat) $sql.=" where idCat='$idCat' ";
        $sql.=" order by $campo $sorti limit $offset, $limit";
        //print $sql;
        return $this->get($sql);
	}
	
	function getTotal($table, $idCat, $procurar="", $filtro=""){
		       
		$where=$this->makeWhere($table, $idCat, $procurar, $filtro);
        
        $sql="select count(*) as total from $table $where";
        //echo $sql;
        $total=$this->get($sql);
        return $total[0]['total'];
	}
	
	/******************************************************************************/
	/******************************************************************************/
	
	
	function setContagem($table, $id){
		$sql="update $table set contagem=contagem + 1 where id='$id'";
		$linha=$this->set($sql);
	}
	
	function getContagem($table){
		$sql="select * from $table order by contagem desc limit 0,5";
		return $this->get($sql);
	}

	
}
?>
