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);
            }
        }
    }
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);
            }
        }
    }
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 ) ; } } }
This query function is used for more advanced SQL queries for which non of the other methods fit
@param string $sql This should be the SQL query which you wish to run
@param array $variables This should be an array of values to execute as the values in a prepared statement
@return array|boolean Returns array of results for the query that has just been run if select or returns true and false if executed successfully or not
This query function is used for more advanced SQL queries for which non of the other methods fit