<?php


define('SERVER', '');
define('UZIVATEL', '');
define('HESLO', '');
define('DATABAZE', '');
define('ZNAKOVASADA', 'utf8');


class Mysql
{

    private static $objekt = null;
    private $mysqli = null;
    private $vysledek;

    public function __construct()
    {
        $this->prihlas();
        $this->dotaz("SET NAMES '" . ZNAKOVASADA . "'");
    }

    public function __destruct()
    {
        @$this->mysqli->close();
    }

    public static function pripojeni()
    {
        if (self::$objekt == null) {
            $class = __CLASS__;
            self::$objekt = new $class;
        }
        return self::$objekt;
    }

    public function prihlas($db = DATABAZE)
    {
        @$this->mysqli = new mysqli(SERVER, UZIVATEL, HESLO, $db);
        if (mysqli_connect_errno()) {
           echo "##" . $db . "##" . PHP_EOL;
            echo("Chyba spojeni s DB");
            exit;
        }
    }

    public function escape($text)
    {
        $text = $this->mysqli->real_escape_string($text);
        return $text;
    }

    public function dotaz($sql)
    {
        if ($value = $this->mysqli->query($sql)) {
            $this->vysledek = $value;
            return $value;
        }
        $this->vysledek = false;
        return false;
    }
    
    public function pocetRadku($vysledek){
        return $vysledek->num_rows;
    }
    
    public function podejRadek()
    {
        if ($this->vysledek) {
            if ($polozka = mysqli_fetch_object($this->vysledek)) {
                return $polozka;
            }
        }
        return false;
    }

}



?>