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

标签 mysql wordpress serialization migration

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

对于插件保存的每条记录,数据都存储在 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,反序列化,重新序列化并更新数据库中的现有值? 我应该将重新序列化的值保存到新表中,然后从该表替换回 wp_options 吗?如何? 否则还有什么其他解决方案?

最佳答案

没有必要这样做,您需要的是按原样导入值。它是一个数组,只要您不以任何方式更改数据,它就可以正常工作。

无论如何,当您将 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()负责序列化的函数。

关于mysql - 反序列化,再次序列化和更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15982797/

相关文章:

python - 使用python将日期时间转换为mysql格式

php - 使用 wp_read_audio_metadata()

wordpress - WordPress仅在每个类别中发布1条帖子

django - 使用来自 JSON 的数据使用 DRF Serializer 更新对象

php - 来自两个表的MYSQL请求

PHP: Controller 中的 Symfony2 MySQL SELECT 查询

PHP/MySQL 在数据库中创建空白记录

wordpress - 如何在 Wordpress 子主题中编译 SASS?

java - 使用 boost::posix_time::ptime 序列化 XML 表示创建 Java 对象

javascript - 在 JS 中读取/写入 float 字节