【发布时间】:2018-10-04 11:33:54
【问题描述】:
我将我的 json 过滤器作为序列化数据存储在我的 postgre 数据库中,插入效果很好。
现在,我需要查询选择,并反序列化我的过滤器。
Postgresql 查询给了我这个数组($results):
array (size=3)
0 =>
array (size=4)
'id_filtres_stock' => int 7
'id_liseo_utilisateurs' => int 46
'filtres' => string 'O:8:"stdClass":1:{s:5:"ville";s:9:"ABBEVILLE";}' (length=47)
'nom_filtre' => null
1 =>
array (size=4)
'id_filtres_stock' => int 8
'id_liseo_utilisateurs' => int 46
'filtres' => string 'O:8:"stdClass":0:{}' (length=19)
'nom_filtre' => string 'test' (length=4)
2 =>
array (size=4)
'id_filtres_stock' => int 9
'id_liseo_utilisateurs' => int 46
'filtres' => string 'O:8:"stdClass":1:{s:7:"nom_pdg";s:16:"AUCHAN BAGNOLET ";}' (length=57)
'nom_filtre' => string 'test' (length=4)
我需要使用 unserialize() 将 'filtres' 转换回来,所以我正在尝试访问 filtres 变量:
echo($results[0][0]->filtres) ;
它不起作用并显示整个数组。
我什至试过这个:
$d = (string)$results[0][0]->filtres;
$d = unserialize($d);
没有运气。
有什么想法吗?
编辑:好的,我现在可以很好地访问它了:
$d = $result[0]['filtres'];
$f = unserialize($d);
谢谢,已解决!
【问题讨论】:
标签: php postgresql serialization