<?php
// Connect Database 
$con = new mysqli("localhost", "root", "db_password", "your_db_name");

if ($con->connect_error) {
    die("Connection Failed ";
}

// Getting Data From DB
$result = $mysqli->query("SELECT name, slug FROM your_table");

// Creating Array
$data = [];
if ($result && $result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
}

// Creating JSON Encoded Data
$jsonData = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);

// Now Saving The  JSON File
file_put_contents("output.json", $jsonData);

$mysqli->close();

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply