CI_DB_active_record::join PHP Method

join() public method

Generates the JOIN portion of the query
public join ( $table, $cond, $type = '' ) : object
return object
    function join($table, $cond, $type = '')
    {
        if ($type != '') {
            $type = strtoupper(trim($type));
            if (!in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'))) {
                $type = '';
            } else {
                $type .= ' ';
            }
        }
        // Extract any aliases that might exist.  We use this information
        // in the _protect_identifiers to know whether to add a table prefix
        $this->_track_aliases($table);
        // Strip apart the condition and protect the identifiers
        if (preg_match('/([\\w\\.]+)([\\W\\s]+)(.+)/', $cond, $match)) {
            $match[1] = $this->_protect_identifiers($match[1]);
            $match[3] = $this->_protect_identifiers($match[3]);
            $cond = $match[1] . $match[2] . $match[3];
        }
        // Assemble the JOIN statement
        $join = $type . 'JOIN ' . $this->_protect_identifiers($table, TRUE, NULL, FALSE) . ' ON ' . $cond;
        $this->ar_join[] = $join;
        if ($this->ar_caching === TRUE) {
            $this->ar_cache_join[] = $join;
            $this->ar_cache_exists[] = 'join';
        }
        return $this;
    }

Usage Example

コード例 #1
0
ファイル: Search_order_scope.php プロジェクト: 119155012/kals
 public function setup_order(CI_DB_active_record $db)
 {
     $db->join('annotation2scope AS order_annotation2scope', 'order_annotation2scope.annotation_id = annotation.annotation_id');
     $db->join('scope AS order_scope', 'order_scope.scope_id = order_annotation2scope.scope_id');
     if ($this->desc === TRUE) {
         $db->select('order_scope.to_index');
         $db->order_by('order_scope.to_index', $this->get_direction());
     } else {
         $db->select('order_scope.from_index');
         $db->order_by('order_scope.from_index');
     }
     return $db;
 }
All Usage Examples Of CI_DB_active_record::join