<?php

$db = new PDO("mysql:dbname=".DB_PARAMS["dbname"].";host=".DB_PARAMS["host"], DB_PARAMS["user"], DB_PARAMS["password"]);

function rawQuery($query, $params =array()): array
{
    global $db;
    $statement = $db->prepare($query);
    $statement->execute($params);
    return $statement->fetchAll();
}

function insertQuery($query, $params =array()): int
{
    global $db;
    $statement = $db->prepare($query);
    if (!$statement->execute($params))
        return 0;
    return $db->lastInsertId();
}

function updateQuery($query, $params =array())
{
    global $db;
    $statement = $db->prepare($query);
    if (!$statement->execute($params))
        return $statement->errorInfo();
    return null;
}

