<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

class Database {
    private $host = "localhost";
    private $db_name = "gyytmfodec_kliv";
    private $username = "gyytmfodec_kliv";
    private $password = "MonKliv1234!";
    public $conn;

    public function getConnection() {
        $this->conn = null;

        try {
            $this->conn = new PDO(
                "mysql:host={$this->host};dbname={$this->db_name};charset=utf8",
                $this->username,
                $this->password
            );
            $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch(PDOException $exception) {
            echo json_encode([
                "success" => false,
                "error" => "Erreur de connexion : " . $exception->getMessage()
            ]);
        }

        return $this->conn;
    }
}
