serialize / unserialize

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am using the serialize and unserialize to put and get data from mysql  
I think i could optimise the way i handle the data, but not really sure how.
What is the best way to happend data to a serialised field?

I currently unserialise, parse the table, and my new value a the end of the  

Is there a quick/better way to do it??

Thanks for your comments.

Re: serialize / unserialize

Quoted text here. Click to load it

Yes, normalise the database, and make sure you don't need to serialize  
anything. What is it you're actually storing, and how, that you wish to  
serialize it and put into one field?
Rik Wasmus

Re: serialize / unserialize

I use it for a document management system, i store all users and hits when a  
document is called.
So basically, i happend the id of the user at the end of the doc.
I am thinking of using uniquearray prior serialising the data..
Is that correct?  

Re: serialize / unserialize

Quoted text here. Click to load it

No, setting up a proper normalised database to hold the information is
the correct way to do it as Rik pointed out.

Re: serialize / unserialize

Captain Paralytic wrote:
Quoted text here. Click to load it

Nice, but not always possible, especially when you're dealing with objects.

For instance, I have a log table for internal errors.  In it I serialize  
an object which contains all the information I need.  But I don't  
necessarily know what that object is.

Of course I could create a table for each type of object, but that's a  
huge waste when we're dealing with something that doesn't log much.  
Rather, I just serialize the object and store it in there.  Later I can  
pull the object out, unserialize it an examine it.

It's very handy when using cURL functions for instance, and having to  
parse the response page.  If there's a parse error, you can later go  
back and get the snapshot of the error, including the page returned  
(which is a member of the object).

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: serialize / unserialize

Quoted text here. Click to load it

array_unique() will remove duplicates, which may or may not be what you  
want, but which is totally besides your original point.

What you want is a separate table checking the user hits.

TABLE documents
TABLE users
TABLE user_doc_hits
Rik Wasmus

Site Timeline