Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unserialize data from mysql

Tags:

php

mysql

in my mysql cell this is stored using serialize function

a:1:{i:0;s:275:"a:4:{s:8:"khghg_id";s:10:"foo1187";s:3:"uri";s:21:"foo/vtory/1187";s:4:"name";s:5:"nmart";s:5:"tuhlmb";a:3:{i:0;s:40:"knuujhs/201205/13_03_pceb9.jpg";i:1;s:40:"knuujhs/201205/13_03_0wlih.jpg";i:2;s:40:"knuujhs/201205/13_03_tq5wf.jpg";}}";}

i am trying to do unserialize

i am using this code

$cell =$row9['attachment'];
$list = unserialize($cell);
$info = unserialize($list[0]);
var_dump($info);

when i am trying with this i am getting error bool(false) error so i tried with parse_str with parse_str i did not get any error

 parse_str($cell,$list );

but i am not getting the output in my database i am storing the output in database and i am submitting the query to database .everything is getting stored other than this unserialize values .here u can note that there are

khghg_id which is foo1187 uri which is foo/vtory/1187 name which is nmart
i want to store these details in my database so i am using

'.$info['khghg_id'].'   for sending the data to mysql but mysql stores everything  other than  all unsterilized  values
like image 783
Steeve Avatar asked May 28 '26 23:05

Steeve


1 Answers

You retrieve a serialized text from database.

You unserialize it.. change it and then when you save it back to database you need to serialize it back

//retrieve serialized data from database
$arr = unserialize($row['properties']);

//get the desired value
$khghg_id = $arr['khghg_id'];

//now insert $khghg_id in database

From the code you posted above.. I see you are unserializing 2 times.. you dont really need to do this

$cell =$row9['attachment'];
$list = unserialize($cell);
$info = $list[0]; //this line should make the difference
var_dump($info);
like image 132
Broncha Avatar answered May 31 '26 13:05

Broncha