How to edit serialized content in mysql











up vote
0
down vote

favorite












I am wondering if it is at all possible to edit an array that was serialized and stored in mysql directly in my mysql?



I am working with a plugin in WordPress that stores an array in mysql (serialized) but I need to change some of the array's values. I was hoping to edit the serialized string in the database but whenever I do the plugin is no longer able to read any of the data.



Is there a way I can edit the serialized data directly without breaking how the plugin reads it?



Cheers!










share|improve this question






















  • php.net/manual/en/function.unserialize.php
    – WillardSolutions
    Nov 5 at 1:51










  • I know how to unserialize it. But I want to edit the serialized string directly in mysql.
    – Chris Hawkins
    Nov 5 at 1:53






  • 1




    That seems like monumentally bad idea.
    – Difster
    Nov 5 at 1:57










  • I don't think this is possible. "serialize" is a language specific function. Not all languages does the same behavior when serializing array. And tho PHP is so clingy with Mr. MySQL, doesn't mean they have the same functions :)
    – ACD
    Nov 5 at 2:05












  • Agree with @Difster. If you want to store data in DB and be able to deal with it - use JSON format. MySQL supports a lot of JSON functions since 5.7 release so you can access data without problem.
    – Anton
    Nov 5 at 12:00















up vote
0
down vote

favorite












I am wondering if it is at all possible to edit an array that was serialized and stored in mysql directly in my mysql?



I am working with a plugin in WordPress that stores an array in mysql (serialized) but I need to change some of the array's values. I was hoping to edit the serialized string in the database but whenever I do the plugin is no longer able to read any of the data.



Is there a way I can edit the serialized data directly without breaking how the plugin reads it?



Cheers!










share|improve this question






















  • php.net/manual/en/function.unserialize.php
    – WillardSolutions
    Nov 5 at 1:51










  • I know how to unserialize it. But I want to edit the serialized string directly in mysql.
    – Chris Hawkins
    Nov 5 at 1:53






  • 1




    That seems like monumentally bad idea.
    – Difster
    Nov 5 at 1:57










  • I don't think this is possible. "serialize" is a language specific function. Not all languages does the same behavior when serializing array. And tho PHP is so clingy with Mr. MySQL, doesn't mean they have the same functions :)
    – ACD
    Nov 5 at 2:05












  • Agree with @Difster. If you want to store data in DB and be able to deal with it - use JSON format. MySQL supports a lot of JSON functions since 5.7 release so you can access data without problem.
    – Anton
    Nov 5 at 12:00













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am wondering if it is at all possible to edit an array that was serialized and stored in mysql directly in my mysql?



I am working with a plugin in WordPress that stores an array in mysql (serialized) but I need to change some of the array's values. I was hoping to edit the serialized string in the database but whenever I do the plugin is no longer able to read any of the data.



Is there a way I can edit the serialized data directly without breaking how the plugin reads it?



Cheers!










share|improve this question













I am wondering if it is at all possible to edit an array that was serialized and stored in mysql directly in my mysql?



I am working with a plugin in WordPress that stores an array in mysql (serialized) but I need to change some of the array's values. I was hoping to edit the serialized string in the database but whenever I do the plugin is no longer able to read any of the data.



Is there a way I can edit the serialized data directly without breaking how the plugin reads it?



Cheers!







php mysql wordpress






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 5 at 1:45









Chris Hawkins

79216




79216












  • php.net/manual/en/function.unserialize.php
    – WillardSolutions
    Nov 5 at 1:51










  • I know how to unserialize it. But I want to edit the serialized string directly in mysql.
    – Chris Hawkins
    Nov 5 at 1:53






  • 1




    That seems like monumentally bad idea.
    – Difster
    Nov 5 at 1:57










  • I don't think this is possible. "serialize" is a language specific function. Not all languages does the same behavior when serializing array. And tho PHP is so clingy with Mr. MySQL, doesn't mean they have the same functions :)
    – ACD
    Nov 5 at 2:05












  • Agree with @Difster. If you want to store data in DB and be able to deal with it - use JSON format. MySQL supports a lot of JSON functions since 5.7 release so you can access data without problem.
    – Anton
    Nov 5 at 12:00


















  • php.net/manual/en/function.unserialize.php
    – WillardSolutions
    Nov 5 at 1:51










  • I know how to unserialize it. But I want to edit the serialized string directly in mysql.
    – Chris Hawkins
    Nov 5 at 1:53






  • 1




    That seems like monumentally bad idea.
    – Difster
    Nov 5 at 1:57










  • I don't think this is possible. "serialize" is a language specific function. Not all languages does the same behavior when serializing array. And tho PHP is so clingy with Mr. MySQL, doesn't mean they have the same functions :)
    – ACD
    Nov 5 at 2:05












  • Agree with @Difster. If you want to store data in DB and be able to deal with it - use JSON format. MySQL supports a lot of JSON functions since 5.7 release so you can access data without problem.
    – Anton
    Nov 5 at 12:00
















php.net/manual/en/function.unserialize.php
– WillardSolutions
Nov 5 at 1:51




php.net/manual/en/function.unserialize.php
– WillardSolutions
Nov 5 at 1:51












I know how to unserialize it. But I want to edit the serialized string directly in mysql.
– Chris Hawkins
Nov 5 at 1:53




I know how to unserialize it. But I want to edit the serialized string directly in mysql.
– Chris Hawkins
Nov 5 at 1:53




1




1




That seems like monumentally bad idea.
– Difster
Nov 5 at 1:57




That seems like monumentally bad idea.
– Difster
Nov 5 at 1:57












I don't think this is possible. "serialize" is a language specific function. Not all languages does the same behavior when serializing array. And tho PHP is so clingy with Mr. MySQL, doesn't mean they have the same functions :)
– ACD
Nov 5 at 2:05






I don't think this is possible. "serialize" is a language specific function. Not all languages does the same behavior when serializing array. And tho PHP is so clingy with Mr. MySQL, doesn't mean they have the same functions :)
– ACD
Nov 5 at 2:05














Agree with @Difster. If you want to store data in DB and be able to deal with it - use JSON format. MySQL supports a lot of JSON functions since 5.7 release so you can access data without problem.
– Anton
Nov 5 at 12:00




Agree with @Difster. If you want to store data in DB and be able to deal with it - use JSON format. MySQL supports a lot of JSON functions since 5.7 release so you can access data without problem.
– Anton
Nov 5 at 12:00












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Unserialize it and then serialize it again. Those are basic php functions.



$array = unserialize($serialized_data);
//do stuff to $array

$serealize = serialize($array);





share|improve this answer





















  • I was thinking that... but the serialized string I get back appears to be different than the string in the database. So maybe they are storing the array in a different manner that simply serializing it.
    – Chris Hawkins
    Nov 5 at 2:03










  • WordPress just uses the PHP serialize/unserialize functions. There's no reason the plugins shouldn't be able to read it, I've done it before. If you or remove characters, elements etc. it does change the string. But it shouldn't render it unreadable. I should add, that I've done this many times.
    – Difster
    Nov 5 at 2:05












  • I ended up just writing some shortcode that pulled the serialized string then ran some code to update the required changes and put it back into the database. That worked.
    – Chris Hawkins
    Nov 5 at 8:20











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147301%2fhow-to-edit-serialized-content-in-mysql%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Unserialize it and then serialize it again. Those are basic php functions.



$array = unserialize($serialized_data);
//do stuff to $array

$serealize = serialize($array);





share|improve this answer





















  • I was thinking that... but the serialized string I get back appears to be different than the string in the database. So maybe they are storing the array in a different manner that simply serializing it.
    – Chris Hawkins
    Nov 5 at 2:03










  • WordPress just uses the PHP serialize/unserialize functions. There's no reason the plugins shouldn't be able to read it, I've done it before. If you or remove characters, elements etc. it does change the string. But it shouldn't render it unreadable. I should add, that I've done this many times.
    – Difster
    Nov 5 at 2:05












  • I ended up just writing some shortcode that pulled the serialized string then ran some code to update the required changes and put it back into the database. That worked.
    – Chris Hawkins
    Nov 5 at 8:20















up vote
0
down vote













Unserialize it and then serialize it again. Those are basic php functions.



$array = unserialize($serialized_data);
//do stuff to $array

$serealize = serialize($array);





share|improve this answer





















  • I was thinking that... but the serialized string I get back appears to be different than the string in the database. So maybe they are storing the array in a different manner that simply serializing it.
    – Chris Hawkins
    Nov 5 at 2:03










  • WordPress just uses the PHP serialize/unserialize functions. There's no reason the plugins shouldn't be able to read it, I've done it before. If you or remove characters, elements etc. it does change the string. But it shouldn't render it unreadable. I should add, that I've done this many times.
    – Difster
    Nov 5 at 2:05












  • I ended up just writing some shortcode that pulled the serialized string then ran some code to update the required changes and put it back into the database. That worked.
    – Chris Hawkins
    Nov 5 at 8:20













up vote
0
down vote










up vote
0
down vote









Unserialize it and then serialize it again. Those are basic php functions.



$array = unserialize($serialized_data);
//do stuff to $array

$serealize = serialize($array);





share|improve this answer












Unserialize it and then serialize it again. Those are basic php functions.



$array = unserialize($serialized_data);
//do stuff to $array

$serealize = serialize($array);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 5 at 1:53









Difster

2,69111729




2,69111729












  • I was thinking that... but the serialized string I get back appears to be different than the string in the database. So maybe they are storing the array in a different manner that simply serializing it.
    – Chris Hawkins
    Nov 5 at 2:03










  • WordPress just uses the PHP serialize/unserialize functions. There's no reason the plugins shouldn't be able to read it, I've done it before. If you or remove characters, elements etc. it does change the string. But it shouldn't render it unreadable. I should add, that I've done this many times.
    – Difster
    Nov 5 at 2:05












  • I ended up just writing some shortcode that pulled the serialized string then ran some code to update the required changes and put it back into the database. That worked.
    – Chris Hawkins
    Nov 5 at 8:20


















  • I was thinking that... but the serialized string I get back appears to be different than the string in the database. So maybe they are storing the array in a different manner that simply serializing it.
    – Chris Hawkins
    Nov 5 at 2:03










  • WordPress just uses the PHP serialize/unserialize functions. There's no reason the plugins shouldn't be able to read it, I've done it before. If you or remove characters, elements etc. it does change the string. But it shouldn't render it unreadable. I should add, that I've done this many times.
    – Difster
    Nov 5 at 2:05












  • I ended up just writing some shortcode that pulled the serialized string then ran some code to update the required changes and put it back into the database. That worked.
    – Chris Hawkins
    Nov 5 at 8:20
















I was thinking that... but the serialized string I get back appears to be different than the string in the database. So maybe they are storing the array in a different manner that simply serializing it.
– Chris Hawkins
Nov 5 at 2:03




I was thinking that... but the serialized string I get back appears to be different than the string in the database. So maybe they are storing the array in a different manner that simply serializing it.
– Chris Hawkins
Nov 5 at 2:03












WordPress just uses the PHP serialize/unserialize functions. There's no reason the plugins shouldn't be able to read it, I've done it before. If you or remove characters, elements etc. it does change the string. But it shouldn't render it unreadable. I should add, that I've done this many times.
– Difster
Nov 5 at 2:05






WordPress just uses the PHP serialize/unserialize functions. There's no reason the plugins shouldn't be able to read it, I've done it before. If you or remove characters, elements etc. it does change the string. But it shouldn't render it unreadable. I should add, that I've done this many times.
– Difster
Nov 5 at 2:05














I ended up just writing some shortcode that pulled the serialized string then ran some code to update the required changes and put it back into the database. That worked.
– Chris Hawkins
Nov 5 at 8:20




I ended up just writing some shortcode that pulled the serialized string then ran some code to update the required changes and put it back into the database. That worked.
– Chris Hawkins
Nov 5 at 8:20


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147301%2fhow-to-edit-serialized-content-in-mysql%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini