<?php

date_default_timezone_set('America/Toronto');

$host = getenv('DB_HOST') ?: 'mis-mysql';
$user = getenv('DB_USER') ?: 'goiintra_root';
$pw = getenv('DB_PASSWORD') ?: 'L0C2CKN5GHHY';
$dbName = getenv('DB_NAME') ?: 'goiintra_db';

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

try {
    $conn = new mysqli($host, $user, $pw, $dbName);
    $conn->set_charset('utf8');
} catch (mysqli_sql_exception $e) {
    error_log($e->getMessage());
    exit('[DB Error. Please contact administrator.]');
}

function qry($qry){
    global $conn;
    return mysqli_query($conn, $qry);
}

function fetch_array($qryResult) {
    return mysqli_fetch_array($qryResult, MYSQLI_ASSOC);
}

function db_insert_id() {
    global $conn;
    return mysqli_insert_id($conn);
}

function db_num_rows($db_query) {
    return mysqli_num_rows($db_query);
}