<?php
    function logError($error,$query="") {
        global $prefix;
        $file=fopen("$prefix/logs/errorlog.txt", "a");
        $msg = getinfo()."\nSql Error: ".$error."\n";
        if ($query != "") $msg.= "Query: ".$query."\n";
        $msg.="Debug Backtrace:\n".getDebugBacktrace()."\n";
        fwrite($file, $msg);
        fclose($file);
        return $error;
    }
    function mysqli_query_wrapper($db_link,$query,$die=true) {
        if ($query) {
            $result = mysqli_query($db_link,$query);
            if ($die && !$result) die (logError(mysqli_error($db_link),$query));
            return $result;
        }
    }
?>