<?php

require_once "config.php";

// Set header to specify content type as JSON
header('Content-Type: application/json');

// Get the HTTP method used
$method = $_SERVER['REQUEST_METHOD'];

// Perform actions based on the HTTP method
switch ($method) {
    case 'GET':
        // Perform SQL injection prevention by using prepared statements
        $query = $conn->prepare("SELECT * FROM tblink LIMIT 1");
        $query->execute(); // Execute the prepared statement
        $result = $query->get_result(); // Get the result set
        $data = $result->fetch_all(MYSQLI_ASSOC); // Fetch all rows of the query result as an associative array
        echo json_encode($data);
        break;
}

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