Try this may be it's help you
$data = array();
if($stmt->execute()){
while ($row = $stmt->fetchAll(PDO::FETCH_ASSOC)) {
$data['data'] = $row;
}
}
}
if(!empty($data)){
header("Access-Control-Allow-Origin: *");//this allows coors
header('Content-Type: application/json');
print json_encode($data);
}else{
echo 'error';
}