<?php
include 'config.php';

$response = array();

$sql = "SELECT * FROM posts ORDER BY created_at DESC";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $posts = array();
    while($row = $result->fetch_assoc()) {
        $posts[] = $row;
    }
    $response['success'] = true;
    $response['posts'] = $posts;
} else {
    $response['success'] = false;
    $response['message'] = "No posts found";
}

echo json_encode($response);
$conn->close();
?>