<?php
header("Content-Type:application/json");
//variables
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ddv";
$table = $_GET['name'];

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

$sql = "SELECT * FROM {$table}";
$query = $conn->query($sql);
while($row = $query->fetch_assoc()){
    $value[] = $row;
}//grab items and put in array

//convert array to json
$value = json_encode($value, JSON_PRETTY_PRINT);


//create json file
file_put_contents("./json/{$table}.json", $value);

echo $value;//return converted json
?>