?
Solved

PHP5: how do I pull serialized data from db?

Posted on 2014-07-25
7
Medium Priority
?
282 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 111

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 111

Expert Comment

by:Ray Paseur
ID: 40220707
0
 

Author Comment

by:epifanio67
ID: 40220727
Thank you Ray,

Really appreciate the tips...

Regards,
0
 
LVL 111

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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

801 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