Solved

PHP5: how do I pull serialized data from db?

Posted on 2014-07-25
7
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 110

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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 110

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 110

Expert Comment

by:Ray Paseur
ID: 40220707
0
 

Author Comment

by:epifanio67
ID: 40220727
Thank you Ray,

Really appreciate the tips...

Regards,
0
 
LVL 110

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

691 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