<?php
// Include DB file for credentials and database connection 


include("db.php");

error_reporting(E_ALL);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
	
	
	
	$data = json_decode(file_get_contents('php://input'), true);
	
	$return = array('success' => false, 'message' => '');
	
	
	$stmt = $conn->prepare("SELECT * FROM tbl_countries order by name");
    $stmt->execute();
    $result = $stmt->get_result();
	
	$rows  = [];
	
    if($result->num_rows > 0) {
	
		while($row = $result->fetch_assoc()) {
			
		    $rows[] = $row;	
		}
		$return = array('success' => true, 'message' => 'Successfully fetched data!', 'data' => $rows);
		
	} else {
		
		$return = array('success' => false, 'message' => 'No record found!..', 'data' => $rows);
		
	}

	$stmt->close();
	$conn->close();
	
	echo json_encode($return);
	
}



