PHP的API响应不显示所有结果

时间:2018-11-07 10:51:28

标签: php mysql zend-framework2 postman postman-collection-runner

我在函数中有一个选择查询,该查询在sql命令提示符下执行,显示所有结果。

但是在邮递员响应中,UserInfo仅显示1条记录作为响应。

protected function getUserSession(){
    $data = $this->params; 

    $sqlquery = "SELECT `Uid` as UID,`CreatedDate"
            . "` as CreatedDate,`Action_key` as ActionKey FROM `UsersOptStatus` ORDER BY Uid DESC LIMIT 10"; 
    $userInfoArray = array();       
    $userInfoArray = $this->getUsersOptStatusTable()->customquery($sqlquery);
    print_r($userInfoArray);

    //$uid =  $this->getUsersNewTable()->uidFromApiKey($data['UserId']);

   return array("errstr"=>"Fetching success.","success"=>1,"data"=>array('UserInfo'=>$userInfoArray));
}


public function customquery($sql) {
    $data = $this->tableGateway->getAdapter()->driver->getConnection()->execute($sql);
    return $data;
}

选择查询结果:

enter image description here

邮递员的实际结果

在原始标签中,所有结果都在获取

enter image description here

在“漂亮”标签中,它显示Bad String

enter image description here

2 个答案:

答案 0 :(得分:0)

好,找到答案了。

使结果集循环。

public function customquery($sql) {
    foreach (($this->tableGateway->getAdapter()->driver->getConnection()->execute($sql)) as $row){
        $results[] = $row;
    }
    return $results;

}

答案 1 :(得分:0)

我建议你:

public function customquery($sql) {
    $data = $this->tableGateway->getAdapter()->driver->getConnection()->execute($sql);
    return iterator_to_array($data);
}