Web / PHP

How to create JSon file from MySQL database using PHP

by Libz Mbanje
25 Nov 2015 at 22:31hrs | 1645 Views
This tutorial assumes you know how to retrieve data from a database (MySQL) using php. If you do not know then its best to check out 'How to retrieve data from MySQL database in php'

Assuming that you have retrieved data from your database and assigned a variable 'myData' to it. myData will be in array form which can be easily converted to JSON using php method json_encode().
In this case we want to customise our the output data to include htm. Note that this

Set header to json using this line of code

 header('Content-Type: application/json');


$myDatabase = new myDatabase();
$myData = $myDatabase->getTable();
echo json_encode($myData);


Source - accessing{CODE}
More on: JSon, MySQL, PHP



Chat Login

Register | Forgot password