CI_DB_active_record::_where PHP Méthode

_where() public méthode

Called by where() or orwhere()
public _where ( $key, $value = NULL, $type = 'AND ', $escape = NULL ) : object
Résultat object
    function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
    {
        if (!is_array($key)) {
            $key = array($key => $value);
        }
        // If the escape value was not set will will base it on the global setting
        if (!is_bool($escape)) {
            $escape = $this->_protect_identifiers;
        }
        foreach ($key as $k => $v) {
            $prefix = (count($this->ar_where) == 0 and count($this->ar_cache_where) == 0) ? '' : $type;
            if (is_null($v) && !$this->_has_operator($k)) {
                // value appears not to have been set, assign the test to IS NULL
                $k .= ' IS NULL';
            }
            if (!is_null($v)) {
                if ($escape === TRUE) {
                    $k = $this->_protect_identifiers($k, FALSE, $escape);
                    $v = ' ' . $this->escape($v);
                }
                if (!$this->_has_operator($k)) {
                    $k .= ' =';
                }
            } else {
                $k = $this->_protect_identifiers($k, FALSE, $escape);
            }
            $this->ar_where[] = $prefix . $k . $v;
            if ($this->ar_caching === TRUE) {
                $this->ar_cache_where[] = $prefix . $k . $v;
                $this->ar_cache_exists[] = 'where';
            }
        }
        return $this;
    }

Usage Example

 /**
  * Where
  *
  * Called by where() or orwhere()
  *
  * @access    private
  * @param    mixed
  * @param    mixed
  * @param    string
  * @return    object
  */
 function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
 {
     // store this as the last_bracket_type
     $this->last_bracket_type = 'where';
     // call the original method
     $result = parent::_where($key, $value, $type, $escape);
     // do we need to add a bracket open
     if ($this->ar_bracket_open) {
         // fetch the key of the last entry added
         end($this->ar_where);
         $key = key($this->ar_where);
         // was this the first entry?
         if ($key == 0) {
             // first where clause, simply prefix it with a bracket open
             $this->ar_where[$key] = '(' . $this->ar_where[$key];
         } else {
             // subsequent where clause, strip the type before adding the bracket open
             $this->ar_where[$key] = $type . ' (' . substr($this->ar_where[$key], strlen($type));
         }
         // reset the bracket state
         $this->ar_bracket_open = FALSE;
         // update the AR cache clauses as well
         if ($this->ar_caching === TRUE) {
             $this->ar_cache_where[$key] = $this->ar_where[$key];
         }
     }
     // return the result
     return $result;
 }