getConnection(); $usrrd = new user($db); // query products $stmt = $usrrd->user_read(); $num = $stmt->rowCount(); //echo $num; // check if more than 0 record found if($num>0){ // products array $userread_arr=array(); $userread_arr["records"]=array(); // retrieve our table contents // fetch() is faster than fetchAll() // http://stackoverflow.com/questions/2770630/pdofetchall-vs-pdofetch-in-a-loop while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ // extract row // this will make $row['name'] to // just $name only extract($row); $userread_item=array( "userbranchcode" => $userbranchcode, "username" => $username, "useremail" => $useremail, "userpass" => $userpass, "userstatus" => $userstatus //$empname,$ts_id,$ts_scantime,$ts_scanloc,$ts_type ); array_push($userread_arr["records"], $userread_item); } // set response code - 200 OK http_response_code(200); // show products data in json format echo json_encode($userread_arr); } ?>