JSON vs. Serialized Array in database

Inez picture Inez · Aug 20, 2009 · Viewed 44.2k times · Source

What are the advantages and disadvantages of storing JSON data in MySQL database vs. serialized array?

Answer

Mark Tomlin picture Mark Tomlin · Nov 12, 2009
  1. JSON encode() & decode()
    • PHP Version >= 5.0.0
      • Nesting Limit of 20.
    • PHP Version >= 5.2.3
      • Nesting Limit of 128.
    • PHP Version >= 5.3.0
      • Nesting Limit of 512.
    • Small footprint vs PHP's serialize'd string.
  2. serialize() & unserialize()
    • PHP Version >= 4.0.0
      • Methods are not lost on PHP Datatype Object.
      • __wakeup() magic method called on any object being unserialize. (VERY POWERFUL)
      • It has been noted that it is some times best the base64 encode strings put into the database, and base64 decode strings taken out of the database with this function, as there are some issues with the handling of some white space characters.

The choice is yours.