user1227914
user1227914

Reputation: 3514

unserializing data array with php from mysql database

I have the following serialized PHP array stored in a mySQL database:

a:2:{i:2070;s:4:"0.00";i:1901;s:4:"1.00";}

Now, I managed to output that value with:

$my_data=mysql_result($result,$i,"my_data");
echo "$my_data";

but I can't manage to unserialize it. I tried this but it doesn't work:

$my_data=unserialize($my_data);

When I add that in between, all I get is a blank page. Any ideas?

Upvotes: 0

Views: 2623

Answers (1)

Gohn67
Gohn67

Reputation: 10638

Maybe you should look at the process of inserting the the value into the database. Is it possible that after the values are serialized, that they were encoded in someway, such as to html entities or something?

I ran a test locally and I got the same error message. Here is output:

a:2:{i:2070;s:4:"0.00";i:1901;s:4:"1.00";} Notice: unserialize(): Error at offset 12 of 62 bytes in /srv/localhost/public_html/test.php on line 6 

Here is code

<?php

$value = htmlentities('a:2:{i:2070;s:4:"0.00";i:1901;s:4:"1.00";}');
echo $value;

unserialize($value);

Upvotes: 3

Related Questions