Solved

PHP5: how do I pull serialized data from db?

Posted on 2014-07-25
7
277 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 108

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 108

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 108

Expert Comment

by:Ray Paseur
ID: 40220707
0
 

Author Comment

by:epifanio67
ID: 40220727
Thank you Ray,

Really appreciate the tips...

Regards,
0
 
LVL 108

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now