Search code examples
phpmysqlzend-framework2postmanpostman-collection-runner

php api response not showing all results


I have a select query in a function, which executed in sql command prompt, displays all results.

But in postman response, UserInfo is showing only 1 record as response.

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;
}

Select Query's result:

enter image description here

Actual Result in Postman

In raw tab, all results are fetching

enter image description here

In Pretty tab, it shows Bad String

enter image description here


Solution

  • Ok found the answer.

    Had the loop the result sets .

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