Search code examples
phpmysqljsondump

Benefits of dumping from a MySQL database to JSON file?


I just want to ask if there would be a difference getting a report from a MYSQL database directly or from a MYSQL database dumped JSON.

I'm new with JSON and is looking everywhere for tutorials and samples so a suggestion is highly appreciated.

My scenario would be getting data from a MYSQL database then dump this information to an external JSON file then process it with PHP.

The question is

  1. Do i need to apply filters when dumping data to my JSON file depending on the users request? If so how will I do this for multiple users provided that they use different filters?

  2. Is it advisable to dump the whole database to JSON from backend? If this is the case what if I have a 100MB worth of JSON file. (I already have 35MB worth of data from a 3 day database, and i need to atleast process a whole month).

  3. If dumping from a JSON file results to an array how can I apply filters to it without looping through the whole array then checking values using IF STATEMENT?

I could always get the data from a MYSQL database directly using PHP. but like I said if this can be done with JSON and would result to a better performing site I would rather go for it.


Solution

  • Please don't do this.

    There is no reason to do this for each request. It will result in worse performance.

    PHP provides all tools in standard language to interact safely with MySQL database.

    Do i need to apply filters when dumping data to my JSON file depending on the users request? If so how will I do this for multiple users provided that they use different filters?

    If you needed to do this for some reason, (don't do it) then yes might as well minimize the data you get from mysql and have to write to the os

    Is it advisable to dump the whole database to JSON from backend? If this is the case what if I have a 100MB worth of JSON file. (I already have 35MB worth of data from a 3 day database, and i need to atleast process a whole month).

    No, it is not advisable to dump any data to a JSON file for a live request. For MYSQL backups it is a good idea to back up mysql data into a file, commonly a .sql file

    If dumping from a JSON file results to an array how can I apply filters to it without looping through the whole array then checking values using IF STATEMENT?

    This illustrates the need for a mysql tutorial. Mysql stores data on your filesystem. It is a highly optimized, battle tested system maed to filter results. Do all filtering in mysql unless you have a really good reason not to