<?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)
{
    $sql = "SELECT * FROM nilai WHERE user_ID = '".$ID."' ORDER BY tes_ke ASC";
    //echo $sql;
    $result = $conn->query($sql);

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

function get_data_person($conn, $ID)
{
    $sql = "SELECT * FROM peserta WHERE ID = '".$ID."'";
    $result = $conn->query($sql)->fetch_assoc();

    //$conn->close();

    return $result;
}

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

    //$conn->close();

    return $result;
}