我在这里做错了什么?我正在序列化一个值,将其存储在数据库(表 bb_meta)中,检索它......到目前为止还可以......但是我必须将它反序列化两次。我不应该只反序列化一次吗?这似乎可行,但我想知道我在这里缺少关于序列化的哪一点。
//check database to see if user has ever visited before.
$querystring = $bbdb->prepare( "SELECT `meta_value` FROM `$bbdb->meta` WHERE `object_type` = %s AND `object_id` = %s AND `meta_key` = %s LIMIT 1", $bbtype, $bb_this_thread, $bbuser );
$bb_last_visits = $bbdb->get_row($querystring, OBJECT);
//if $bb_last_visits is empty, add time() as the metavalue using bb_update_meta
if (empty($bb_last_visits)) {
$first_visit = time();
echo 'serialized first visit: ' . $bb_this_visit_time_serialized = serialize(array($bb_this_thread => $first_visit));
bb_update_meta( $bb_this_thread, $bbuser, $bb_this_visit_time_serialized, $bbtype ); //add to database, bb_meta table
echo '$bb_last_visits was empty. Setting first visit time as ' . $bb_this_visit_time_serialized . '<br>';
} else {
//else, test by unserializing the data for use.
echo 'last visit time already set: '; echo $bb_last_visits->meta_value; echo '<br>';
//fatal error - echo 'unserialized: ' . $bb_last_visits_unserialized = unserialize($bb_last_visits[0]->meta_value); echo '<br>';
echo 'unserialize: ' . $unserialized_visits = unserialize($bb_last_visits->meta_value); echo '<br>';
echo 'hmm, need to unserialize again??: '; echo $unserialized_unserialized_visits = unserialize($unserialized_visits); echo '<br>';
echo 'hey look, it\'s an array value I can finally use now. phew: ' . $unserialized_unserialized_visits[$bb_this_thread];
}