Last active
July 13, 2017 08:37
-
-
Save lablnet/45d74dbb127ea28008bd57cfc798fea6 to your computer and use it in GitHub Desktop.
How to export database records in json file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try{ | |
$db = new PDO("mysql:host=localhost;dbname=lablnet_cms", "root" ,""); | |
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); | |
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); | |
}catch(Exception $e){ | |
die($e->getMessage()); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once "db.php"; | |
$sth=$db->prepare("select * from users"); | |
$sth->execute(); | |
while($row = $sth->fetchObject()) | |
{ | |
$id=$row->id; | |
$fname = $row->fname; | |
$lname = $row->lname; | |
$username = $row->username; | |
$email = $row->email; | |
$password = $row->password; | |
$profile_picture = $row->profile_picture; | |
$profile_cover = $row->profile_cover; | |
$background = $row->background; | |
$about = $row->about; | |
$bio = $row->bio; | |
$work = $row->work; | |
$status = $row->status; | |
$created = $row->created; | |
$privacy = $row->privacy; | |
$ban = $row->ban; | |
$facebook = $row->facebook; | |
$gmail = $row->gmail; | |
$youtube = $row->youtube; | |
$twitter = $row->twitter; | |
$point = $row->point; | |
$records[] = array( | |
'id'=> $id, | |
'First name' => $fname, | |
'Last name' => $lname, | |
'username' => $username, | |
'email' => $email, | |
'password' => $password, | |
'profile_picture' => $profile_picture, | |
'profile_cover' => $profile_cover, | |
'background' => $background, | |
'about' => $about, | |
'bio' => $bio, | |
'work' => $work, | |
'status' => $status, | |
'created' => $created, | |
'privacy' => $privacy, | |
'ban' => $ban, | |
'facebook' => $facebook, | |
'gmail' => $gmail, | |
'youtube' => $youtube, | |
'twitter' => $twitter, | |
'point' => $point, | |
); | |
} | |
$response['users'] = $records; | |
$fp = fopen('exportsfiles/users.json', 'w'); | |
fwrite($fp, json_encode($response , JSON_PRETTY_PRINT)); | |
fclose($fp); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//when script extecute its generate following file | |
{ | |
"users": [ | |
{ | |
"id": "27", | |
"First name": "Malik", | |
"Last name": "Umer Farooq", | |
"username": "malik", | |
"email": "lablnet01@gmail.com", | |
"password": " sQyukFSIkr8E", | |
"profile_picture": "iFV6H913VVXBDjDVBF0fLGV 4VOHpPss8s5 CVGy9Esc3hJSV9.jpg", | |
"profile_cover": "uwFfVrGQgFohmOsoD6fO4QSD75YFKFGGSDEGWPGPvSRNDG9HDH.jpg", | |
"background": "VjSDGZHAFFsfY6fGvkfQr4Iy1bIDEHxKHGFvkdGsguFVzsVyAV.jpg", | |
"about": "", | |
"bio": "", | |
"work": "", | |
"status": "active", | |
"created": "2017-06-11 21:22:53", | |
"privacy": "public", | |
"ban": null, | |
"facebook": "sadad", | |
"gmail": "gfdgdgfgf", | |
"youtube": "adad", | |
"twitter": "adad", | |
"point": "288" | |
}, | |
{ | |
"id": "29", | |
"First name": "Malik", | |
"Last name": "farooq", | |
"username": "farooq", | |
"email": "farooq@gmail.com", | |
"password": "VGOKKRr83.Cyw", | |
"profile_picture": "oVSl14 VS5CwBD8XS8QOjffpDBibJXbnDDVAS4ro3R8cusabwG.jpg", | |
"profile_cover": "YfxXV0gPRAsVEQmsqKD0w4PfKYSdXGlVDfAgHsuHEESjCfDwEb.jpg", | |
"background": null, | |
"about": "", | |
"bio": "", | |
"work": "", | |
"status": "active", | |
"created": "2017-06-24 22:30:23", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "30", | |
"First name": "aqeel", | |
"Last name": "aqeel", | |
"username": "aqeelaqeel", | |
"email": "aqeel@gmail.com", | |
"password": "yHgavCFTgyOSQ", | |
"profile_picture": "UVqnsAgScGUEDWDEmHD4Hh76PiSf6b VADsFSsDPvH2VffQHfH.jpg", | |
"profile_cover": "BUHPHLyGLTkVhH28c93VG9RDHVVcrxWGgGGFVzlGGDeFP8D0nS.jpg", | |
"background": "SieHOGIG1WobxV2e7FlGqVZsKsLDS2OUHfs DdH9SAVAxHHwjS.jpg", | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-06-28 01:12:21", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "42", | |
"First name": "Ameer hamza", | |
"Last name": "hamza", | |
"username": "ameer", | |
"email": "hameer013@gmail.com", | |
"password": "vSsj21QjBDn3Y", | |
"profile_picture": "DOkHVgtfl9gGXCL0fiHISG0ffXUDQohAawfmSQVHfspEWDcSWP.jpg", | |
"profile_cover": "mfFF7DaGsjJDZkYV7HkSs1spxcECG0bVg7bGsosIYk6ss5FFYE.jpg", | |
"background": "X28FRVDSwiSgGHVbN9gVMBGV3sOGinggVVvVYZaFGs8PtRDJVs.jpg", | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-07-06 18:49:21", | |
"privacy": "public", | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "8" | |
}, | |
{ | |
"id": "43", | |
"First name": "Umer", | |
"Last name": "Umer Farooq", | |
"username": "username", | |
"email": "lablnet01@gmail.com", | |
"password": "ch.oG99idd5EU", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-07-12 02:09:06", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "44", | |
"First name": "Umer", | |
"Last name": "Umer Farooq", | |
"username": "malsdsik", | |
"email": "lablnet01@gmail.com", | |
"password": "TD7G14o3OfG7w", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-07-12 02:09:33", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "45", | |
"First name": "Umer", | |
"Last name": "Umer Farooq", | |
"username": "malsdsik", | |
"email": "lablnet01@gmail.com", | |
"password": "VSQ06rcM5aqug", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-07-12 02:10:03", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "46", | |
"First name": "Umer", | |
"Last name": "Umer Farooq", | |
"username": "malsdsik", | |
"email": "lablnet01@gmail.com", | |
"password": "UGE3tu0l.\/Ilw", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-07-12 02:10:22", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "47", | |
"First name": "Umer", | |
"Last name": "Umer Farooq", | |
"username": "malsdsik", | |
"email": "lablnet01@gmail.com", | |
"password": "5E02jqmE3\/H7Y", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-07-12 02:12:16", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "48", | |
"First name": "Umer", | |
"Last name": "Umer Farooq", | |
"username": "malsdsik", | |
"email": "lablnet01@gmail.com", | |
"password": "9Vpr.E9d5gguI", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-07-12 02:12:38", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "49", | |
"First name": "Umer", | |
"Last name": "Umer Farooq", | |
"username": "malsdsik", | |
"email": "lablnet01@gmail.com", | |
"password": "F4x5aVdy6GG9U", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-07-12 02:16:12", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "50", | |
"First name": "Umer", | |
"Last name": "Umer Farooq", | |
"username": "malsdsik", | |
"email": "lablnet01@gmail.com", | |
"password": "VUJIiYxJUyHx6", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-07-12 02:16:51", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "51", | |
"First name": "dsdsdsd", | |
"Last name": "Umer Farooq", | |
"username": "malik", | |
"email": "lablnet01@gmail.com", | |
"password": "VglfrP1mFPE0s", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-07-12 02:17:00", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "52", | |
"First name": "dadasda", | |
"Last name": "asd", | |
"username": "malik", | |
"email": "farooq@gmail.com", | |
"password": " sAU4KpvtNVq6", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "active", | |
"created": "2017-07-12 02:18:18", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "53", | |
"First name": "sfdfsdfsdf", | |
"Last name": "Umer Farooq", | |
"username": "malikdfsfsfsf", | |
"email": "labfsfsfsfsflnet01@gmail.com", | |
"password": "gGXmIXyyJ2Twg", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "unactive", | |
"created": "2017-07-13 00:23:06", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
}, | |
{ | |
"id": "54", | |
"First name": "<script>alert(1);<\/script>", | |
"Last name": "Umer Farooq", | |
"username": "fadaddsfsdfsdfsdf", | |
"email": "labsddsadasdasdlnetssdas01@gmail.com", | |
"password": "CsENTqmd1elTg", | |
"profile_picture": null, | |
"profile_cover": null, | |
"background": null, | |
"about": null, | |
"bio": null, | |
"work": null, | |
"status": "unactive", | |
"created": "2017-07-13 00:24:12", | |
"privacy": null, | |
"ban": null, | |
"facebook": null, | |
"gmail": null, | |
"youtube": null, | |
"twitter": null, | |
"point": "0" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment