Here, before going through the program, we need to create a MySQL database in our localhost server. PHP is used to connect with the localhost server and to fetch the data from the database table present in our localhost server by evaluating the MySQL queries. Wampserver helps to start Apache and MySQL and connect them with the PHP file. In our PHP code, we are going to make an array of data fetched from the database and then convert them into JSON. A dynamic JSON file will be created to store the array of JSON objects.
Consider, we have a database named gfg, a table named userdata. Now, here is the PHP code to fetch data from database and store them into JSON file named gfgfuserdetails.json by converting them into an array of JSON objects.
The dynamic JSON file created after running the code on the browser:
- How to fetch data from localserver database and display on HTML table using PHP ?
- Create a database on Relational Database Service (RDS) of Amazon Web Services(AWS)
- How to fetch data from JSON file and display in HTML table using jQuery ?
- How to send data of HTML form directly to JSON file?
- Fetching text from Wikipedia's Infobox in Python
- Export JSON to CSV file in Angular
- How to read and write JSON file using Node.js ?
- How to update dependency in package.json file ?
- How to work with Node.js and JSON file ?
- How to Convert CSV to JSON file having Comma Separated values in Node.js ?
- How to create an array for JSON using PHP?
- MongoDB | Create Database using MongoShell
- How to load data from JSON into a Bootstrap Table?
- PHP program to fetch data from localhost server database using XAMPP
- How to fetch data from Database in PHP PDO using loop ?
- Spring Boot | How to access database using Spring Data JPA
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.