php - Retrieve serialize value in the database wordpress -
i'm trying query serialized array value in database in wordpress, value stored in table wp_postmeta, in column meta_value. well, first stored array using serialize() function of php. example,
$postid = 1; $arr = array(1, 2, 3); $ser_val = serialize($arr); update_meta_data($postid, '_customvalue', $ser_val);
the stored values this
s:30:"a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}";
then when tried retrieve performing wordpress sql query.. expecting array since stored array, after doing so, display string not array.
$get_score = $wpdb->get_row("select meta_value wp_postmeta meta_key = '_cummulativescore'"); $scr = unserialize($get_score->meta_value); var_dump($scr); //output displayed //string(30) "a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}"
i did check value using is_array() function, result is not array thought on serialize value array?
it looks info converted string during serialization.
the info should stored as
a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}
instead of
s:30:"a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}"
s:30 means string length 30.
php mysql arrays wordpress serialization
No comments:
Post a Comment