0

I am working on a simple multiplayer game that may have 2 to 6 people in a game at a time. The game is only slightly more complex than Five-Card Draw poker so it isn't very resource intensive.

In order to make the development fast and easy I am thinking about having a table like this: (simplified)

games
    id (int) primary-key auto-inc > unique id
    data (text) > for storing a JSON string

Here is what I'm thinking for the process:

  • AJAX post includes game_id field
  • Do some permissions checking and validation
  • I fetch the entry from games with the id equal to game_id
  • json_decode the data field
  • More permissions and validation stuff
  • If changes to the game data are made: json_encode the new data and update the DB

Question: What pitfalls may I encounter doing this?

azBrian
  • 661
  • 1
  • 5
  • 19
  • possible duplicate of [Storing Data in MySQL as JSON](http://stackoverflow.com/questions/3564024/storing-data-in-mysql-as-json) – Boaz Jan 05 '15 at 23:31
  • Not a duplicate... i'm not asking anything about CouchDB and I am not askind "n00b" questions about JSON. – azBrian Jan 06 '15 at 04:25

1 Answers1

2

some people do that, here is what you are going to face

(1) every time you need to update the user data, you will have to decode the json data, edit it and then store it (more data to be retrieved, more data to be stored => more processing)
(2) forget about data aggregation using MySQL queries, you will have to do it manually through PHP or what ever language you use

I can't say it is a bad or good idea to store JSON in MySQL, that depends on the application domain and your use

Abdo Adel
  • 1,177
  • 2
  • 17
  • 30
  • (1) I could expect a performance impact compared to using standard relational database requests... but arguably if each decode/encode replaces the uses of multiple selects/inserts/updates it could offset that. (2) Very strong and sound reason NOT to do it the way I am thinking. Thanks Abdo! – azBrian Jan 06 '15 at 04:31