Doctrine\DBAL\Query\QueryBuilder::andWhere PHP Method

andWhere() public method

$qb = $conn->createQueryBuilder() ->select('u') ->from('users', 'u') ->where('u.username LIKE ?') ->andWhere('u.is_active = 1');
See also: where()
public andWhere ( mixed $where )
$where mixed The query restrictions.
    public function andWhere($where)
    {
        $args = func_get_args();
        $where = $this->getQueryPart('where');
        if ($where instanceof CompositeExpression && $where->getType() === CompositeExpression::TYPE_AND) {
            $where->addMultiple($args);
        } else {
            array_unshift($args, $where);
            $where = new CompositeExpression(CompositeExpression::TYPE_AND, $args);
        }
        return $this->add('where', $where, true);
    }

Usage Example

Beispiel #1
0
 public function finalizeQuery(\Doctrine\DBAL\Query\QueryBuilder $query)
 {
     $paramcount = 0;
     if (isset($this->gID) && $this->gID > 0) {
         $query->where('gID = ?')->setParameter($paramcount++, $this->gID);
     }
     switch ($this->sortBy) {
         case "alpha":
             $query->orderBy('pName', 'ASC');
             break;
         case "date":
             $query->orderBy('pDateAdded', 'DESC');
             break;
     }
     switch ($this->featured) {
         case "featured":
             $query->andWhere("pFeatured = 1");
             break;
         case "nonfeatured":
             $query->andWhere("pFeatured = 0");
             break;
     }
     if ($this->activeOnly) {
         $query->andWhere("pActive = 1");
     }
     if ($this->search) {
         $query->andWhere('pName like ?')->setParameter($paramcount++, '%' . $this->search . '%');
     }
     return $query;
 }
All Usage Examples Of Doctrine\DBAL\Query\QueryBuilder::andWhere