简体   繁体   English

从mysql反序列化数据

[英]unserialize data from mysql

in my mysql cell this is stored using serialize function 在我的mysql单元格中,这是使用serialize函数存储的

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 当我尝试这个我得到错误bool(错误)错误所以我尝试与parse_str与parse_str我没有得到任何错误

 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 khghg_id是foo1187 uri,这是foo / vtory / 1187名称是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

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 从你上面发布的代码..我看到你正在反序列化2次..你真的不需要这样做

$cell =$row9['attachment'];
$list = unserialize($cell);
$info = $list[0]; //this line should make the difference
var_dump($info);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM