[wp-hackers] How do you store multiple plugin options

Mike Schinkel mikeschinkel at newclarity.net
Wed Mar 24 19:34:59 UTC 2010


On Mar 24, 2010, at 2:42 PM, Otto wrote:
> MySQL has search and replace capabilities which work very nicely,
> actually, and they can search and replace inside serialized data just
> as easily as they can in non-serialized data. You don't need a
> developer to adjust things. 

I'm not wading into this debate but am curious how MySQL can replace data back into the database for PHP serialized data?  Let's take, for example, the option for the Twenty Ten template (line break in the email are only for clarity):

	option_name: 
		mods_Twenty Ten

	option_value: 
		a:2:{s:12:"header_image";
			s:66:"http://example.com/wp-content/uploads/2010/03/header.png";
			s:16:"background_image";
			s:70:"http://example.com/wp-content/uploads/2010/03/background.jpg";}

Now if I run this in MySQL:

	UPDATE wp_options
	SET option_value = REPLACE(option_value,'/header.png','/new-header.png')
	WHERE option_name='mods_Twenty Ten'

...it will corrupt the data from PHP's unserialize perspective because the string lengths will no longer be correct. 

Is there some other way to update PHP Serialized arrays directly in MySQL that I do not know about?

-Mike
	


More information about the wp-hackers mailing list