I’m building and iOS application which fetches data from my MYSQL database, so to do such thing i need to use JSON (i know other methods,but i need specifically to use JSON). The problem is, how can i fetch data from my mysql database and write it to file in JSON format (preferably using PHP).
Any link,tutorial or source code will be much appreciated!
Retrieve your database rows into an array and write the output of
json_encode()to the output buffer with the appropriate header:From the browser’s perspective, it is receiving a JSON file, though PHP is serving it.
If you actually need to save the JSON file rather than just output it, use
file_put_contents()