ORM::_run PHP Method

_run() protected method

Execute the SELECT query that has been built up by chaining methods on this class. Return an array of rows as associative arrays.
protected _run ( )
    protected function _run()
    {
        $query = $this->_build_select();
        $caching_enabled = self::$_config[$this->_connection_name]['caching'];
        if ($caching_enabled) {
            $cache_key = self::_create_cache_key($query, $this->_values, $this->_table_name, $this->_connection_name);
            $cached_result = self::_check_query_cache($cache_key, $this->_table_name, $this->_connection_name);
            if ($cached_result !== false) {
                return $cached_result;
            }
        }
        self::_execute($query, $this->_values, $this->_connection_name);
        $statement = self::get_last_statement();
        $rows = array();
        while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
            $rows[] = $row;
        }
        if ($caching_enabled) {
            self::_cache_query_result($cache_key, $rows, $this->_table_name, $this->_connection_name);
        }
        // reset Idiorm after executing the query
        $this->_values = array();
        $this->_result_columns = array('*');
        $this->_using_default_result_columns = true;
        return $rows;
    }

Usage Example

 /**
  * Execute the SELECT query that has been built up by chaining methods
  * on this class. Return an array of rows as associative arrays.
  */
 protected function _run()
 {
     // allow parent method to run
     if (!$this->cnt_query) {
         // need a way to make sure this is set
         if ($this->_is_raw_query) {
             if (is_array($this->_raw_parameters)) {
                 foreach ($this->_raw_parameters as $k => $v) {
                     if (!is_numeric($v)) {
                         $v = '"' . $v . '"';
                     }
                     $this->_raw_query = str_replace(':' . $k, $v, $this->_raw_query);
                 }
             }
         }
         return parent::_run();
     }
     // we are not caching the COUNT - @todo - implement caching
     $query = $this->_build_select();
     parent::_execute($query, $this->_values, $this->_connection_name);
     $statement = parent::get_last_statement();
     $rows = array();
     while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
         $rows[] = $row;
     }
     // reset Idiorm bound values
     $this->_values = array();
     return $rows;
 }
ORM