我想在我的表“区”中加载我的所有行“name”。
我已经可以阅读第一行但不会更多。
我的控制器:
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');
}
在我的Controller中,我有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"
}
只有第一行......如何才能转换读取功能,以便加载所有行?
答案 0 :(得分: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()
返回一个rowset对象(行对象数组)或异常/致命错误。
答案 1 :(得分:0)
if ($row = $table->fetchRow($select)) {
return $row->toArray();
}
将该部分代码更改为
return $your_database_object->fetchAll($select);