Gdn_SQLDriver::where PHP Method

where() public method

Adds to the $this->_Wheres collection. Called by $this->Where() and $this->OrWhere();
public where ( mixed $Field, mixed $Value = null, boolean $EscapeFieldSql = true, $EscapeValueSql = true ) : Gdn_SQLDriver
$Field mixed The string on the left side of the comparison, or an associative array of Field => Value items to compare.
$Value mixed The string on the right side of the comparison. You can optionally provide an array of DatabaseFunction => Value, which will be converted to DatabaseFunction('Value'). If DatabaseFunction contains a '%s' then sprintf will be used for to place DatabaseFunction into the value.
$EscapeFieldSql boolean A boolean value indicating if $this->EscapeSql method should be called on $Field.
return Gdn_SQLDriver $this
    public function where($Field, $Value = null, $EscapeFieldSql = true, $EscapeValueSql = true)
    {
        if (!is_array($Field)) {
            $Field = array($Field => $Value);
        }
        foreach ($Field as $SubField => $SubValue) {
            if (is_array($SubValue)) {
                if (count($SubValue) == 1) {
                    $firstVal = reset($SubValue);
                    $this->where($SubField, $firstVal);
                } else {
                    $this->whereIn($SubField, $SubValue);
                }
            } else {
                $WhereExpr = $this->conditionExpr($SubField, $SubValue, $EscapeFieldSql, $EscapeValueSql);
                if (strlen($WhereExpr) > 0) {
                    $this->_where($WhereExpr);
                }
            }
        }
        return $this;
    }

Usage Example

 /** Add the sql to perform a search.
  *
  * @param Gdn_SQLDriver $Sql
  * @param string $Columns a comma seperated list of columns to search on.
  */
 public function addMatchSql($Sql, $Columns, $LikeRelavenceColumn = '')
 {
     if ($this->_SearchMode == 'like') {
         if ($LikeRelavenceColumn) {
             $Sql->select($LikeRelavenceColumn, '', 'Relavence');
         } else {
             $Sql->select(1, '', 'Relavence');
         }
         $Sql->beginWhereGroup();
         $ColumnsArray = explode(',', $Columns);
         $First = true;
         foreach ($ColumnsArray as $Column) {
             $Column = trim($Column);
             $Param = $this->Parameter();
             if ($First) {
                 $Sql->where("{$Column} like {$Param}", null, false, false);
                 $First = false;
             } else {
                 $Sql->orWhere("{$Column} like {$Param}", null, false, false);
             }
         }
         $Sql->endWhereGroup();
     } else {
         $Boolean = $this->_SearchMode == 'boolean' ? ' in boolean mode' : '';
         $Param = $this->Parameter();
         $Sql->select($Columns, "match(%s) against({$Param}{$Boolean})", 'Relavence');
         $Param = $this->Parameter();
         $Sql->where("match({$Columns}) against ({$Param}{$Boolean})", null, false, false);
     }
 }
All Usage Examples Of Gdn_SQLDriver::where