public function query($sql, $variables = array(), $cache = true) {
        if(!empty(trim($sql))){
            $this->sql = $sql;
            $this->key = md5($this->sql.serialize($variables));
            if($this->logQueries) {$this->writeQueryToLog();}
            if($cache && $this->cacheEnabled && $this->getCache($this->key)) {
                return $this->cacheValue;
            }
            try{
                $this->query = $this->db->prepare($this->sql);
                $result = $this->query->execute($variables);
                if(strpos($this->sql, 'SELECT') !== false) {
                    $result = $this->query->fetchAll(PDO::FETCH_ASSOC);
                    if($cache && $this->cacheEnabled) {$this->setCache($this->key, $result);}
                }
                return $result;
            }
            catch(\Exception $e) {
                $this->error($e);
            }
        }
    }