<?php
/** @var TYPE_NAME $db_server */
/** @var TYPE_NAME $db_user */
/** @var TYPE_NAME $db_password */
/** @var TYPE_NAME $db_database */
/** @var TYPE_NAME $db_port */

include_once($_SERVER['DOCUMENT_ROOT'] . '/config.php');
$GLOBALS['conn'] = mysqli_connect($db_server, $db_user, $db_password, $db_database, $db_port);
if (!$GLOBALS['conn']) {
    echo "Fout bij verbinden met de database" . PHP_EOL;
    die();
}

try {
    $dsn = "mysql:host=$db_server;dbname=$db_database;port=$db_port;charset=utf8mb4";
    $username = $db_user;
    $password = $db_password;

    $GLOBALS['pdo'] = new PDO($dsn, $username, $password, [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // Throw exceptions on errors
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,       // Fetch associative arrays by default
        PDO::ATTR_EMULATE_PREPARES => false,                  // Use real prepared statements
    ]);
} catch (PDOException $e) {
    echo "Fout bij verbinden met de database: " . $e->getMessage() . PHP_EOL;
    die();
}