<?php

class Database
{
    private string $host = "localhost";
    private string $dbname = "smartprint";
    private string $username = "root";
    private string $password = "";

    private ?PDO $connection = null;

    public function connect(): PDO
    {
        if ($this->connection === null) {

            $this->connection = new PDO(

                "mysql:host={$this->host};dbname={$this->dbname};charset=utf8mb4",

                $this->username,

                $this->password,

                [
                    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                    PDO::ATTR_EMULATE_PREPARES => false
                ]

            );

        }

        return $this->connection;
    }
}