Forum Moderators: open

Message Too Old, No Replies

Storing an Array into a MySQL Table

Not practical to store each key as different MySQL cell

         

otem

4:27 pm on Mar 16, 2007 (gmt 0)

10+ Year Member



Hello,

I'm trying to store an Array into a MySQL table.

This table will hold lots of different types of arrays, each with unique data types and numbers of keys. It is therefore not practical to try to break up the array into different cells.

One important thing to note is that the data in the array will not be sorted or called for by its information. Other cells with be called upon, and then the associated information in the array for that cell will be read.

I'm thinking maybe I can "flatten" out my array, similar to the print_r($array) function, but I wouldn't know how to do this to a variable, (or even if its possible or a good idea.)

Any suggestions would greatly be appreciated.

justageek

10:37 pm on Mar 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use serialize(). Works great to store anything such as $_GET or $_POST data or any other array.

To get around some problems that can happen trying to do an insert into the table you need to clean the serialized string. An easy way to do it is to base64 encode it if you don't mind a bit of bloated data.

JAG