• 10
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Storing JSON in MySQL database? [duplicate]

Yes, it's a very good idea to use mysql as a key-value store, in fact facebook does for some uses.

CREATE TABLE `json` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `data` blob NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

The above table-structure will get you far. It's very easy to shard or cluster.

Edit: The point here is to use PHP, Ruby etc to handle the json/data. You do SELECT ..., do your edits, then INSERT ... ON DUPLICATE KEY UPDATE ....

  • 12
Reply Report
      • 2
    • The OP may need to query some of the data in the JSON, so this may not be the best idea.
      • 1
    • This works fine if the JSON can be stored as a key-value pairs without any children nodes. What if the JSON heirarchy is deeper? ex: fields have children which in-turn have children objects? which is not feasible to store in a RDBMS.

Storing more than one piece of data in a relational database field is generally wrong. It is possible to think of cases where it would be acceptable, but not for storing an entire user.

If a using a relational database structure is not sufficient you may want to look at a NoSQL database inestead of MySQL.

  • 2
Reply Report

I think it is not. What about four months later you decide add a new attribute to your entity or remove some attributes from your entity? How will you parse your old json contents? If you dont know how many columns you will need in your table, you should think in a different way and maybe create a dynamic structure like using user_column table

  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions