<?php
require dirname(dirname(__FILE__)) . '/inc/Connection.php';

class Prozigzig
{
    private $probus;

    public function __construct()
    {
        $this->probus = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
        if ($this->probus->connect_error) {
            die("Connection failed: " . $this->probus->connect_error);
        }
        if (!$this->probus->set_charset("utf8mb4")) {
            echo "Warning: Error loading character set utf8mb4: " . $this->probus->error;
        }
    }

    

    
	
    public function login(string $username, string $password, string $tblname): int
    {
		$this->probus->set_charset("utf8mb4");
		
			 
        $query = ($tblname == "admin") ?
            "SELECT * FROM admin WHERE username=? AND password=?" :
            "SELECT * FROM $tblname WHERE email=? AND password=?";
        $stmt = $this->probus->prepare($query);
        $stmt->bind_param("ss", $username, $password);
        $stmt->execute();
        $stmt->store_result();
        $count = $stmt->num_rows;
        $stmt->close();
        return $count;
		
    }
    
	
}
?>
