

<?php
// Include the database configuration
include("db_config.php");

// Set header to return JSON
header('Content-Type: application/json');

// Create a MySQL connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// SQL query to fetch all donor records
$sql = "SELECT * FROM donation_tbl";
$result = $conn->query($sql);

// Check if there are records
if ($result->num_rows > 0) {
    $donors = array();

    // Fetch all records
    while($row = $result->fetch_assoc()) {
        $donors[] = $row;
    }

    // Return the donor records as JSON
    echo json_encode(["message" => "Donors fetched successfully", "donors" => $donors]);
} else {
    echo json_encode(["message" => "No donors found"]);
}

// Close the database connection
$conn->close();
?>

