<?php

function connect_db()
{
    $server = "localhost";
    $user = "uptbahas_user1";
    $pass = "uptbahas_user1";
    $db = "uptbahas_esertifikat";

    $conn = new mysqli($server, $user, $pass, $db);

    if($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    return $conn;
}

function get_nilai_by_ID($conn, $ID, $date)
{
    $sql = "SELECT a.*, b.nip, b.nama, DATE(a.created_at) as tgl_ttd FROM nilai a, pejabat b WHERE a.user_ID = '".$ID."' AND a.tes_tgl = '".$date."'";
    //echo $sql;
    $result = $conn->query($sql)->fetch_assoc();

    //$conn->close();
    return $result;
}

function get_data_person($conn, $ID)
{
    //$sql = "SELECT ID, nama, fakultas, jurusan_ps, jenjang, DATE_FORMAT(DATE('1899-12-30') + INTERVAL tgl_lahir DAY, '%d/%m/%Y') as normal_tgl_lahir FROM peserta WHERE ID = '".$ID."'";
    $sql = "SELECT ID, nama, fakultas, jurusan_ps, jenjang, tgl_lahir as normal_tgl_lahir FROM peserta WHERE ID = '".$ID."'";
    $result = $conn->query($sql)->fetch_assoc();

    //$conn->close();

    return $result;
}