<?php
// App/Kernel/Database.php

class Database {
  protected $pdo;

  public function __construct() {
    $this->pdo = new PDO('mysql:host=localhost;dbname=dykqnvjf_gespes360;charset=utf8mb4', 'dykqnvjf_gespes360', 'dykqnvjf_gespes360');
    $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  }

  public static function connect() {
    return new PDO('mysql:host=localhost;dbname=dykqnvjf_gespes360', 'dykqnvjf_gespes360', 'dykqnvjf_gespes360', [
      PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
      PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"
    ]);
    }

  public function fetchAll($sql, $params = []) {
    $stmt = $this->pdo->prepare($sql);
    $stmt->execute($params);
    return $stmt->fetchAll(PDO::FETCH_ASSOC);
  }

  public function fetch($sql, $params = []) {
    $stmt = $this->pdo->prepare($sql);
    $stmt->execute($params);
    return $stmt->fetch(PDO::FETCH_ASSOC);
  }

  public function execute($sql, $params = []) {
    $stmt = $this->pdo->prepare($sql);
    return $stmt->execute($params);
  }

}
?>