code: protected function query($sql)
      {
          $GLOBALS['current_sql'] = $sql;
  
          $app = \FelixOnline\Base\App::getInstance();
  
          $item = null;
          if ($this->cache == true) {
              $item = $app['cache']->getItem($this->table.'/'.md5($sql));
              $results = $item->get(\Stash\Invalidation::PRECOMPUTE, 300);
          }
  
          if ($item && !$item->isMiss()) {
              return $results;
          }
  
          set_error_handler(function ($errno, $errstr) {
              $sql = $GLOBALS['current_sql']; // $sql in query function not in scope here - this is a nasty hack
              unset($GLOBALS['current_sql']);
  
              throw new SQLException($errstr, $sql);
          });
          $results = $app['db']->get_results($sql);
          restore_error_handler(); // restore old error handler
  
          if ($app['db']->last_error) {
              unset($GLOBALS['current_sql']);
              throw new SQLException($app['db']->last_error, $app['db']->captured_errors);
          }
  
          if ($item) {
              if ($this->cacheExpiry) {
                  $item->expiresAfter($this->cacheExpiry);
              }
              $app['cache']->save($item->set($results));
          }
  
          unset($GLOBALS['current_sql']);
  
          return $results;
      }
docs: Query sql