Fetch All Record From Database & Write Data in Jason File
<?php
$conn=mysqli_connect('localhost:3308','root','','vritant_db');
$sql = "SELECT * FROM vritant_tbl";
$result= mysqli_query($conn,$sql);
$count= mysqli_num_rows($result);
if ($count>0) {
while ($data = mysqli_fetch_assoc($result)) {
$arr[]=$data;
}
$arr = json_encode($arr,JSON_PRETTY_PRINT);
$file = "my-".date('d-m-y').".json";
if (file_put_contents("json/{$file}",$arr)) {
echo "json/{$file} is created";
}else{
echo "{$file} is not created";
}
}
Data in Json File
[
{
"id": "1",
"name": "Happy",
"email": "h@gmail.com",
"mobile": "8005106019",
"password": "Hbc@123123",
"payment": "3000"
},
{
"id": "24",
"name": "VRITANT",
"email": "singhjai96599@gmail.com",
"mobile": "6391467375",
"password": "aa",
"payment": "10000"
},
{
"id": "26",
"name": "VRITANT RAJBHAR",
"email": "jay@gmail.com",
"mobile": "8005106019",
"password": "Vbc@123123",
"payment": "3000"
},
{
"id": "28",
"name": "Anish",
"email": "anish@gmail.com",
"mobile": "78555555",
"password": "bb",
"payment": "20000"
},
{
"id": "29",
"name": "Divya",
"email": "divya@gmail.com",
"mobile": "8888888888",
"password": "Alkjaslfindsf487e489t94t4t",
"payment": null
},
{
"id": "30",
"name": "Rahul",
"email": "rahul@gmail.com",
"mobile": "777777777777",
"password": "Bnkjsdfdsnfsd87343y57erh",
"payment": null
},
{
"id": "32",
"name": "VRITANT",
"email": "singhjaiff96599@gmail.com",
"mobile": "+9116391467375",
"password": "asdfgh",
"payment": null
},
{
"id": "33",
"name": "VRITANT",
"email": "singhjai96rr599@gmail.com",
"mobile": "+446391467375",
"password": "asdfghjkhgfd",
"payment": null
},
{
"id": "34",
"name": "VRITANT",
"email": "singhj@gmail.com",
"mobile": "+9116391467375",
"password": "asdffffffffffffhsdf",
"payment": null
},
{
"id": "35",
"name": "VRITANT",
"email": "singhjai9@gmail.com",
"mobile": "+9116391467375",
"password": "deepak",
"payment": null
},
{
"id": "36",
"name": "VRITANT",
"email": "singhjaiss@gmail.com",
"mobile": "+9116391467375",
"password": "ff",
"payment": null
},
{
"id": "37",
"name": "VRITANT",
"email": "singhjai99@gmail.com",
"mobile": "+9116391467375",
"password": "hh",
"payment": null
},
{
"id": "38",
"name": "DEEPAK",
"email": "deepakji542@gmail.com",
"mobile": "07355983816",
"password": "deepak",
"payment": null
}
]
0 Comments