反序列化,再次序列化和更新值

时间:2013-04-13 00:22:05

标签: mysql wordpress serialization migration

我正在处理已迁移的WordPress,网站网址已更改,除了插件存储的一些序列化数据外,一切正常。

对于插件保存的每条记录,数据存储在 wp_options表 option_value列中。 所以数据仍然存在,问题是当url发生变化时,它没有被重新序列化(字符串内容的计数仍然认为它是旧的url长度),因此插件无法正常工作。

因此,为了准确找到需要更新的记录,我使用

$t1 = $wpdb->prefix . "vslider";
$t2 = $wpdb->prefix . "options"; 

$records_ineed = $wpdb->get_results("SELECT * FROM '".$t1."', '".$t2."' WHERE '".$t1."'.option_name='".$t2."'.option_name");

这给了我完全需要重新序列化的记录(它与插件表中创建的记录的名称相匹配,并在wp_option表中创建了记录)

我现在该怎么办?! 我如何只取每个的option_value,反序列化它,重新序列化它并更新db中的现有值? 我应该将重新编码的值保存到新表中,然后从该表替换回wp_options吗?怎么样? 其他什么是其他解决方案?

1 个答案:

答案 0 :(得分:1)

没有必要这样做,你需要的是将值导入为 - 是。它是一个数组,只要你不以任何方式改变数据就可以正常工作。

无论如何,当您导入将wp站点迁移到另一个URL时,绝对不需要逐个读取wp-options表的列。

您需要做什么只是从原始(old-domain)站点转储SQL,然后导入new-domain,然后运行这些查询:

/**
To update WordPress options with the new blog location, use the following SQL command:
**/

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

/**
After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as abolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:
**/

UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');

/**
If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:
**/

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

仅用于验证,在运行这些命令后,返回选项表并验证您的home和site_url函数是否与new-domain数据一样正确。

如果您仍然想要,出于某些不明原因,手动将数据直接插入选项表(??为什么),那么您应该考虑使用get_post_meta()update_post_meta()函数来处理序列化。