Jump to content

Storing Json Data on one Field vs slitting to Multiple Fields


huseyin
 Share

Recommended Posts

I am planning to create a Footbal Statistics website.
The data for this website will be pulled with api requests to different endpoints.

What i want to ask is which of the below methods should i use for better performance:

Method 1 (Store only Json data in one field)
Store whole Json package in one textarea field. 
$page->jsondata = (the whole json package);
For output on the website read this one field like
$fixture = $pages->find(...); and extract all needed data from the jsonpackae filed like
echo "Home Team : ".$fixture->jsondata->response->fixture->teams->home->name." vs Away Team".$jsondata->response->fixture->teams->away->name;

Method 2 (Store all data in seperate fileds. Nearly 100 fields.)
Extract the Json Data and store each data in seperate fields, like;
$page->home_team_name = $jsondata->response->fixture->teams->home->name;
$page->away_team_name = $jsondata->response->fixture->teams->away->name;
$page->save();
For output:
$fixture = $pages->find(.....); and use it like this:
echo "Home Team : ".$fixture->home_team_name." vs Away Team".$fixture->away_team_name;

Sorry for my bad English hope you can understand the question.


 

Link to comment
Share on other sites

  • huseyin changed the title to Storing Json Data on one Field vs slitting to Multiple Fields

Based on nothing but gut feeling, the second. That's the way I did it last time I was importing JSON from somewhere, mainly because I was glad to be able to stop thinking about the horrible JSON object and concentrate on nice PW fields. If you were going to be really careful, some benchmarking might be in order, but I suspect there wouldn't be much in it, just what you're more comfortable dealing with.

  • Like 1
Link to comment
Share on other sites

I'd vote for Method 3: A custom DB table 😛😉 

Sorry but giving an elaborate answer here is very difficult and depends on so many things. So my recommendation above is just to give you an idea of another option that might be good to think of. Having JSON can also be a good option, especially if your DB setup supports it: https://dev.mysql.com/doc/refman/8.0/en/json.html

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...