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).

10
  • How is that going into the database? Or: why not use serialize and deserialize ? Commented Apr 15, 2013 at 15:45
  • I control this process, but i've already gone ahead and stored like thousands of rows of data and it's gnna be a real heave to get that stored as seralize or json again. :( choice? Commented Apr 15, 2013 at 15:46
  • You stored the output of print_r() and expect to be able to parse it again? Commented Apr 15, 2013 at 15:48
  • Why do you use a database then? Anyway you should be able to migrate to another schema, no matter how many "thousands" rows of data you have - that's the purpose of programming! Commented Apr 15, 2013 at 15:48
  • Tip: don't do it again. Don't put serialized data in a database; create a proper schema. Commented Apr 15, 2013 at 15:49

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Better is not to serialize and put proper data in a database. That is what they are for.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.