我在使用 zend-db 时遇到问题,当我使用 时fetchall()
,行返回重复,例如:
{
"title" : "Florianópolis",
"neighborhoods" : [ {
"0" : "6",
"1" : "Abraão",
"name" : "Abraão",
"number" : "6"
},
{
"0" : "9",
"1" : "Açores",
"name" : "Açores",
"number" : "9"
},
{
"0" : "5",
"1" : "Agronômica",
"name" : "Agronômica",
"number" : "5"
},
如您所见,我收到了他们的姓名和电话号码的两倍。这是获取信息的方法:
public function getNeighborhoodsByCity( $city )
{
try
{
$this -> sql = new Sql( $this -> adapter );
$select = $this -> sql -> select();
$select -> from( $this -> table );
$select -> columns( array( 'number',
'name' ) );
$select -> where( "city = '{$city}'" );
$select -> order( "name" );
$statement = $this -> sql -> prepareStatementForSqlObject( $select );
$result = $statement -> execute() -> getResource() -> fetchall();
}
catch ( \Exception $e )
{
throw new \Exception ( 'ERROR : ' . $e -> getMessage() );
}
return $result;
}
我想知道是什么产生了0
and 1
。顺便说一句,我正在学习 Zf3,因此非常欢迎任何改进此代码的提示!提前致谢!