public function fetchAll() { $sql = $this->sqlBase(); $query = new ZendT_Db_Recordset($this->_table->getAdapter()->query($sql, $this->_binds), $this->_columnsMapper); return $query->getRows(); }
/** * Retorna os registros da tabela * * @param array|ZendT_Db_Where $where * @param array|string $columns * @param array|string $orderBy */ public function getRows($where = null, $columns = null, $orderBy = null, $type = false, $lock = false) { if ($columns == null || $columns == '') { $columns = array('*'); } if ($orderBy == null || $orderBy == '') { $orderBy = array('1'); } if (is_string($columns)) { $columns = array($columns); } if (is_string($orderBy)) { $orderBy = array($orderBy); } if (is_array($where)) { $_where = new ZendT_Db_Where('AND'); foreach ($where as $column => $value) { //$_where->addFilter($column, $value); $_where->addFilter($column, $value, '=', $this->_mapper, true); } $where = $_where; $binds = $where->getBinds(); $cmdwhere = $where->getSqlWhere(); } elseif ($where instanceof ZendT_Db_Where || $where instanceof ZendT_Db_Where_Group) { $binds = $where->getBinds(); $cmdwhere = $where->getSqlWhere(); } elseif (is_numeric($where)) { $cmdwhere = 'id = :id'; $binds = array('id' => $where); } elseif (is_string($where)) { $cmdwhere = $where; } elseif (is_int($where)) { $cmdwhere = 'id = :id'; $binds = array('id' => $where); } elseif ($where === null) { $cmdwhere = '1 = 1'; $binds = array(); } else { $cmdwhere = '1 = 1'; $binds = array(); } $sql = 'SELECT ' . implode(',', $columns) . ' FROM ' . $this->getTableName() . ' ' . $this->getAlias() . ' WHERE ' . $cmdwhere; $sql .= ' ORDER BY ' . implode(',', $orderBy); if ($lock) { $sql .= ' FOR UPDATE'; } $stmt = $this->getAdapter()->query($sql, $binds); if ($this->_columnMappers == '') { $this->_columnMappers = new ZendT_Db_Column_Mapper(); $this->_columnMappers->add('default', $this->_mapper); /* foreach ($columns as $column){ $this->_columnMappers->add($column, $this->_mapper); } */ } if ($type) { $recordset = new ZendT_Db_Recordset($stmt, $this->_columnMappers, $type); } else { $recordset = new ZendT_Db_Recordset($stmt); } return $recordset->getRows(); }