Solved

PHP5: how do I pull serialized data from db?

Posted on 2014-07-25
7
279 Views
Last Modified: 2014-07-25
Hello Experts,

Steps:
1. Insert serialized data into db
ex: $serializedSessionData = serialize($sessiondata);
it looks something like this:
a:3:{s:4:"time";a:1:{s:5:"start";s:5:"23:30";}s:2:"UA";a:1:{i:0;s:72:"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0";}s:2:"IP";a:1:{i:0;s:9:"127.0.0.1";}}

how do I pull serialized data from db? In other words, if I want to assign the "UA" value to a variable, how do I do that?

If I am too vague, please let me know I can try to clarify....

Regards,
0
Comment
Question by:epifanio67
  • 4
  • 3
7 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40220671
You pull the serialized data, then use PHP unserialize().

But don't do that.  Instead use JSON.  It's a more universal notation than PHP serialized data, and it accomplishes the same thing.

If you want the value of "UA" you can get it from $sessiondata before you encode it into a string.
0
 

Author Comment

by:epifanio67
ID: 40220687
Thank you Ray,

I was afraid I had to unserialize the data first... too much code...
I was hoping to treat it as an obj array somehow...

I will try JSON...

Regards,
0
 

Author Closing Comment

by:epifanio67
ID: 40220688
Thank you Ray
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40220702
Thanks for the points.  When I've had to store large amounts of "serialized" data in the past (stuff from APIs and the like) I usually pulled out a few key search elements and put them into separate columns of the table.  Then you can store the long JSON string as a "text" data type.  If most of the search queries are satisfied by the separate columns you will get pretty good performance.  If your query misses on the separate columns you can fall back to make a fulltext search on the long JSON string.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40220707
0
 

Author Comment

by:epifanio67
ID: 40220727
Thank you Ray,

Really appreciate the tips...

Regards,
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40220770
Glad to help.  If you need examples or have any questions about it, we will be here!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question