| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace App;
- use Dotenv\Dotenv;
- use Dotenv\Exception\ValidationException;
- use Exception;
- require "vendor/autoload.php";
- try {
- $dotenv = Dotenv::createImmutable(__DIR__);
- $dotenv->load();
- $dotenv->required(["DB_HOST", "DB_USERNAME", "DB_PASSWORD", "DB_NAME"]);
- $dotenv->required(["DIR_ROOT", "TIMEZONE", "LOCALE", "SESSION_NAME", "ENV"])->notEmpty();
- $_ENV["ROOT_DIR"] = __DIR__;
- }
- catch(ValidationException $e) {
- echo $e->getMessage();
- exit();
- }
- try {
- Database::connect(
- $_ENV["DB_HOST"],
- $_ENV["DB_USERNAME"],
- $_ENV["DB_PASSWORD"],
- $_ENV["DB_NAME"]
- );
- }
- catch(Exception $e) {
- View::include("header");
- View::include("error", ["message" => "Unable to establish connection to the database. Please try again later."]);
- View::include("footer");
- exit();
- }
- chdir($_ENV["ROOT_DIR"]);
|