I’ve been developing an application and I’ve run into a situation where I would like to take a snapshot of the current data.
For example, in this application, users will have varying stats and be able to enter matches. How they place in the matches depends on their stats. When the matches are determined the application will pull all of the user’s current stats and determine their points to see who wins.
Now after a match is over I want users to be able to view past matches and the problem arises when I want to display what the participants points were at the time of the match. I would think it would be acceptable to store an array structured like so:
array(
array(username, points),
array(username, points),
etc.
)
Now normalizing the data may be the best practice normally but in this situation:
- There can be anywhere between 2 and 25 participants in a match.
- The data will never be updated, only read.
- I would think having it in an array structure in the database will save me time from having to construct an array in my back-end code.
- EDIT: The data is not permanent. Match records will be deleted 7 days after the match has ended.
Can anyone tell me if this solution will provide any problems?
EDIT
I would be saving the data after serializing the array so in my database I would have a table called ‘matches’ and it would have a column called ‘results’.
The rows for this column would contain serialized arrays. So if the array looked as such:
$array["a"] = "Foo";
$array["b"] = "Bar";
$array["c"] = "Baz";
$array["d"] = "Wom";
Then the row in the database would look like this:
a:4:{s:1:"a";s:3:"Foo";s:1:"b";s:3:"Bar";s:1:"c";s:3:"Baz";s:1:"d";s:3:"Wom";}
If you’re really committed to the use cases you’ve outlined in the question along with the qualification in your comment to Sean Johnson, then I don’t see any problems with your approach.
I still might qualify that by suggesting that you normalize the data if you think there’s a chance you’ll want to be able to mine historical information, but dumping an array into the database as a long lived (relatively speaking) sort of cache might make sense. In other words, store it in both formats, but the main line of the use case you’ve outlined would just hit the array format, but you’d still have the data in a queryable form if you ever wanted it.