Zend Framework 2 – Where Clause-Collection of common programming errors

I would like to add a where clause with this method.

public function fetchAll()
{
    $resultSet = $this->select();
    return $resultSet;
}

I have added like this.

public function fetchAll()
{
    $resultSet = $this->select();
    $resultSet->where("status = ?", 1);
    return $resultSet;
}

But, it shown the below error.

Fatal error: Call to undefined method Zend\Db\ResultSet\ResultSet::where()

Could you please help me to add WHERE, OR WHERE, GROUP and ORDER with above mentioned method.

  1. Hopefully this will help you out:

        public function Profile($accountid)
        {
            $result = $this->select(function (Select $select) use ($accountid) {
                $select
                    ->columns(array(
                        'datefrom',
                        'available',
                        'used',
                        'details'
                    ))
                    ->where($this->adapter->getPlatform()->quoteIdentifier('accountid') . ' = ' . $this->adapter->getPlatform()->quoteValue($accountid));
            });
    
            $row = $result->current();
    
            if (!$row) {
                throw new \Exception('could_not_find_row');
            }
    
            return $row;
        }
    
  2. You can also do $sql->select()->where(array('status' => 1)) or $table->select(array('status' => 1)) (annoying, wish they used the same syntax).

    You pass where an associative array with the mapping column => value (and since it’s an array you can give it multiple clauses). Diemuzi’s way is good for complex identifiers but this is a more readable way for simple comparison.

Originally posted 2013-11-10 00:10:52.