mysql中的WP序列化查询

时间:2018-09-12 12:13:23

标签: php mysql wordpress serialization

我有一个简单的问题,但已经被锁了几个小时...我有一个Wordpress数据库,想更新usermeta表。

该值是使用maybe_serialize()WP函数的序列化值。 我的更新查询每次都会失败。我尝试了多种方法来逃避值,但这是行不通的。

这是我要生成的最终MySQL查询(由PhpMyAdmin生成):

UPDATE `mytable` SET `meta_value` = 'a:2:{s:64:\"261d0952a424f1e8ef27ee77ef505c445c0aac5166f67e8d675bf06f717972d2\";a:4:{s:10:\"expiration\";i:1526328393;s:2:\"ip\";s:14:\"212.71.232.248\";s:2:\"ua\";s:117:\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15\";s:5:\"login\";i:1525118793;}s:64:\"6f04a963506c545e0fb307135bd2eaf5178c8830c55048bb5d80cb7a8d730507\";a:4:{s:10:\"expiration\";i:1525556847;s:2:\"ip\";s:14:\"212.71.232.248\";s:2:\"ua\";s:121:\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36\";s:5:\"login\";i:1525384047;}}' WHERE `mytable`.`umeta_id` = 48;

meta_value的原始内容是:

a:2:{s:64:"261d0952a424f1e8ef27ee77ef505c445c0aac5166f67e8d675bf06f717972d2";a:4:{s:10:"expiration";i:1526328393;s:2:"ip";s:14:"212.71.232.248";s:2:"ua";s:117:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15";s:5:"login";i:1525118793;}s:64:"6f04a963506c545e0fb307135bd2eaf5178c8830c55048bb5d80cb7a8d730507";a:4:{s:10:"expiration";i:1525556847;s:2:"ip";s:14:"212.71.232.248";s:2:"ua";s:121:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36";s:5:"login";i:1525384047;}}

如何在PHP中对其进行转义以获取与MySQL一起使用的最终所需查询?我尝试了mysqli_real_escape_string(),但是不一样。

编辑:这是mysqli_real_escape_string()之后的数组结果

$ a:2:{s:64:\"261d0952a424f1e8ef27ee77ef505c445c0aac5166f67e8d675bf06f717972d2\";a:4:{s:10:\"expiration\";i:1577790000;s:2:\"ip\";s:14:\"212.71.232.248\";s:2:\"ua\";s:117:\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15\";s:5:\"login\";i:1525118793;}s:64:\"6f04a963506c545e0fb307135bd2eaf5178c8830c55048bb5d80cb7a8d730507\";a:4:{s:10:\"expiration\";i:1577790000;s:2:\"ip\";s:14:\"212.71.232.248\";s:2:\"ua\";s:121:\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36\";s:5:\"login\";i:1525384047;}}

如您所见,转义与PhpMYAdmin在第一个查询中生成的转义不同。

谢谢!

0 个答案:

没有答案