Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Evolt.org:
Keeping Arrays Safely Stored
Sep 11, 2003 @ 12:11:28

There's a new "quickie" posting over on Evolt.org this morning that's a good read for anyone that's ever tried to store an entire array in a database before.

Now, obviously, you could create fields for each entry in the array, storing the values in the corresponding fields, but this new article proposes a much simpler way - and it involves serialize(). A serialized array is nothing more than a string of numbers, letters, colons and braces. This can quickly and easily be stored in a common text field. Then, to pull the data out, all you have to do is fetch it from the database, unserialize, and assign it to your array variable. See? simple...

Of course, this method has its down sides as well. It's harder to change the information in that array because of the extra step in between. You'd almost have to write a "serializeAPI" to work with it as easy as you would a normal PHP array...

tagged:

Link:


Trending Topics: