1

我想在我的表“地区”中加载我所有的列“名称”行。

我已经可以阅读第一行,但不能再多读了。

我的控制器:

public function showdataAction()
    {
        $districtMapper = new Backoffice_Model_DistrictMapper();
        $array = $districtMapper->read();    
        Zend_Debug::dump($array);     
    }

我的地区地图:

public function read()
    {
        $table = $this->_dbTable;    
        $columns = array('wijk' => 'wijk',   'coords' => 'coords', );    
        $select = $table->select() ->from($table, $columns) ->order('wijk ASC');
        if ($row = $table->fetchRow($select)) {
           return $row->toArray();
        }    
       throw new Exception('The requested data cannot be found');
    }

在我的控制器中,我有 Zend_Debug::dump($array) ,结果是:

array(2) {
  ["wijk"] => string(10) "Binnenstad"
  ["coords"] => string(2186) "3.72448685517794,51.0601522198842,
                 0 3.72577413282654,51.0597215800093,0 3.72594328459339,
                 51.0600395135711,0 3.72699385985136, 51.060876600363,
                 0 3.72764765694006,51.0608474287073,
                 0 3.7281167878913,51.0605006616679,0 3.72955689560896,
                 51.059999738927"
}

只有第一行......我怎样才能转换读取功能,以便我可以加载所有行?

4

2 回答 2

1
public function read()
    {
        $table = $this->_dbTable;    
        $columns = array('wijk' => 'wijk',   'coords' => 'coords', );    
        $select = $table->select() ->from($table, $columns) ->order('wijk ASC');
        //try/catch might make more sense as fetchAll() returns an object or an exception.
        $result = $table->fetchAll($select)

        return $result->toArray();

    }

更改fetchRow()fetchAll()fetchRow()返回一个行对象或 null,fetchAll()返回一个行集对象(行对象数组)或异常/致命错误。

于 2013-01-23T09:59:16.570 回答
0
if ($row = $table->fetchRow($select)) {
           return $row->toArray();
       }

将那部分代码更改为

return $your_database_object->fetchAll($select);
于 2013-01-22T13:18:34.073 回答