phpapi响应未显示所有结果

uinbv5nw  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(316)

我在函数中有一个select查询,它在sql命令提示符下执行,显示所有结果。
但在 Postman 的回应中, 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;
}

选择查询结果:

Postman 的实际结果
在raw选项卡中,所有结果都是获取的

在“漂亮”选项卡中,它显示 Bad String

xn1cxnb4

xn1cxnb41#

好的,我找到答案了。
让循环得到结果集。

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

}
o4tp2gmn

o4tp2gmn2#

我建议你:

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

相关问题