Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have years of experience with PHP and MySQL, but just starting to develop plugins for WordPress and need some help.

Currently, I am working on a plugin that will add extra functionality to another plugin. I need to read the data stored by the original plugin and manipulate it with my plugin. So far so good, but when I open phpMyAdmin the data stored in the Original plugin table looks like this: a:2:{i:0;a:11:{s:2:"id";s:1:"1";s:7:"item_id";s:1:"1";s:4:"name";s:9:"section 1";s:5:"limit";s:1:"1";s:5:"order";s:6:"random";s:10:"difficulty";s:4:"easy";s:9:"timestamp";s:19:"2012-05-21 12:29:44";s:9: ... Can someone tell me how to read this. How is this method for storing data called and are there guides on how to read this data with other plugins.

EDIT: After further studding the code here is what I understand
- s:2:"id"; this means: string with 2 character -> "id".
- s:7:"item_id"; this means: string with 7 character -> "item_id".

- a:4:{} this means there will be 4 arguments between the curly brackets.

The only thing I could not figure out is that is the i:0;?

Am I right with the above assumptions?

Thanks, Radi.

share|improve this question
    
That's serialized data, and it generally means that you should be modifying it through code, not directly. However, yes, the s is a string, the a is an array, and the i stands for "int" which is just a numeric value. i:0 means an integer of zero. –  Otto May 21 '12 at 21:21
    
You are right that I should not modify it directly, but it will help me build my tables better if I understand the data that is going to be stored in them. Vice versa - use the data from the table with a plugin... –  Radi May 22 '12 at 13:06
add comment

1 Answer

up vote 3 down vote accepted

This is a serialized array. PHP is able to read them as if they were regular arrays (or objects, in some cases) by using the serialize and unserialize functions (WordPress does this for you).

All you need with WordPress to do is use get_option (or comparable WordPress function calls to retrieve data) and use the array/object as normal.

I would recommend you avoid editing the data raw in the database, since can really mess things up (I know from experience :) ).

share|improve this answer
    
isn't get_options only for wp_options table? I need to read data from a custom table(e.g. plugin_name_all_results) –  Radi May 21 '12 at 19:02
1  
If you're reading from a custom table, you'll need to write your own CRUD api. Fortunately, there is '$wpdb`, WordPress' database connection and all around great utility, to make your life easier: codex.wordpress.org/Class_Reference/wpdb –  chrisguitarguy May 21 '12 at 19:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.