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 ?
- How to send data of HTML form directly to JSON file?
- How to fetch data from JSON file and display in HTML table using jQuery ?
- Create a database on Relational Database Service (RDS) of Amazon Web Services(AWS)
- How to create an array for JSON using PHP?
- Export JSON to CSV file in Angular
- How to work with Node.js and JSON file ?
- How to update dependency in package.json file ?
- How to read and write JSON file using Node.js ?
- MongoDB | Create Database using MongoShell
- How to load data from JSON into a Bootstrap Table?
- How to fetch data from Database in PHP PDO using loop ?
- PHP program to fetch data from localhost server database using XAMPP
- Fetching text from Wikipedia's Infobox in Python
- How to Convert Data URI to File then append to FormData?
- Spring Boot | How to access database using Spring Data JPA
- How to import data from .CSV file into MySQL table using Node.js ?
- Reading and Writing data to excel file using Apache POI
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.