0

I have a problem. In my MySQL database, I have a column storing the output of a PHP object (as a string):

Array
(
    [item_id] => 849
    [title] =>
         Array
         (
             [0] => hello
             [1] => bye bye
         )
    ......

If I run eval on that, it ofcourse will not work. Is there a function or known technique to getting this back into a php object, or will i have to store in mysql as json (that will be a massive pain).

Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233

1 Answers1

1

This is the way to go you need either use serialize/unserialize or json strings:

http://php.net/manual/en/language.oop5.serialization.php

Mehdi Karamosly
  • 5,388
  • 2
  • 32
  • 50
  • 1
    Better is not to serialize and put proper data in a database. That is what they are for. – Bart Friederichs Apr 15 '13 at 15:53
  • 1
    Bart, i am getting objects from an API... In this instance, I'm doing it correctly, I just made a mistake of not storing it as json first. The API layout changes often and so creating a database structure for this information would be a waste of time. – Jimmyt1988 Apr 15 '13 at 15:54