<?php

$host = "localhost"; // MySQL server hostname
$username = "root"; // MySQL username
$password = ""; // MySQL password
$database = "rahisient"; // MySQL database name
$port = 3306; // MySQL server port (usually 3306)

// Create a MySQL connection
$conn = new mysqli("$host:$port", $username, $password, $database);

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

// Perform SQL query to retrieve products
$sql = "SELECT * FROM products";
$result = mysqli_query($conn, $sql);

// Create array to hold products
$products = array();

// Loop through results and add to array
while ($row = mysqli_fetch_assoc($result)) {
    $products[] = $row;
}

// Return array as JSON
echo json_encode($products);

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