Custom MySQLi statement function for binding variables
An obligatory suggestion: you can greatly improve any mysqli code by switching to PDO. So your function would be three times shorter 

function db ($query, $parameters = false)
{
    global $db;
    if(!isset($db))
    {
        $options = array(
            PDO::ATTR_ERRMODE            =&gt; PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_ASSOC,
            PDO::ATTR_EMULATE_PREPARES   =&gt; FALSE,
        );
        $dsn = 'mysql:host=localhost;dbname=db;charset=utf8';
        $db = new PDO($dsn, "username", "password", $options);
    }

    if (!$parameters)
    {
        return $db-&gt;query($query);
    } else {
        $stmt = $db-&gt;prepare($query);
        $stmt-&gt;execute($parameters);
        return $stmt;
    }
}


note that PDO has much better equivalent of your db_fetch() function, letting you to get the data simpler and in more formats than your awkward $results / $fetch combination:

$row = db("SELECT * FROM t WHERE id=?", [$id])-&gt;fetch();
$count = db("SELECT count(*) FROM t")-&gt;fetchColumn();
$data = db("SELECT name, id FROM t")-&gt;fetchAll(PDO::FETCH_KEY_PAIR);


compare these explicit calls where you always can tell what does your code return with your 

 $data = db("SELECT name, id FROM t", true, true);


show this code to someone and ask what's in $data. Or look at this code after a couple of months and try to tell it yourself without confusing all these true ans false parameters.