<?php

namespace App\Config;

use PDO;
use PDOException;

class DatasourceConfig
{

    public function connect()
    {
        try {
            $dsn = sprintf(
                "mysql:host=%s;port=%s;dbname=%s;charset=utf8mb4",
                env("DB_HOST"),
                env("DB_PORT"),
                env("DB_NAME")
            );

            $pdo = new PDO(
                $dsn,
                env("DB_USERNAME"),
                env("DB_PASSWORD")
            );

            $pdo->exec("SET time_zone = '+07:00'");

            return $pdo;
        } catch (PDOException $e) {
            die($e->getMessage());
        }
    }
}
