So I logged on phpmyadmin, went to check out how data is stored in a table and saw it”s ‘data’ columns contents (pasted below):

a:8:{i:2;O:8:"stdClass":2:{s:5:"label";s:6:"Vardas";s:5:"value";s:1:"A";}i:3;O:8:"stdClass":2:{s:5:"label";s:8:"Pavardė";s:5:"value";s:1:"G";}i:1;O:8:"stdClass":2:{s:5:"label";s:11:"El. paštas";s:5:"value";s:6:"verynicemail@email.com";}i:4;O:8:"stdClass":2:{s:5:"label";s:7:"Adresas";s:5:"value";s:1:"e";}i:5;O:8:"stdClass":2:{s:5:"label";s:8:"Tel. nr.";s:5:"value";s:1:"3";}i:6;O:8:"stdClass":2:{s:5:"label";s:7:"Mie";s:5:"value";s:7:"Vilnius";}i:7;O:8:"stdClass":2:{s:5:"label";s:5:"Ly";s:5:"value";s:7:"M";}i:8;O:8:"stdClass":2:{s:5:"label";s:11:"Gimimo data";s:5:"value";s:10:"2016-05-12";}}

I know this is a std Object simply passed to the database table’s row. How do I convert this data to a usable format (array or object)?

Or better else – what are the commands typically used in WP to store data in a database table’s column, so I can find the plugin’s source and edit it myelf.

Any help much appreciated.

1 Answer
1

You unserialize() it.

Be aware that most WordPress functions will automatically unserialize() database content before using it. See, for example, the Used By list for maybe_unserialize(). This is by no mean an exhaustive list, I’m sure.

But if you’re retrieving data directly from the database — because there’s not a WordPress function to achieve what you need to do — you’ll need to unserialize() the results.

For example:

$x = $wpdb->get_results( '{your SQL query}' );
// $x will be a serialized string
$unserialized_results = unserialize( $x );

The example you provide actually appears to be an array of 8 stdObjects, with keys from 1 to 8 (unless I’m reading it wrong, which is definitely possible). So that array would be what’s in $unserialized_results at the end of my code snippet.

Leave a Reply

Your email address will not be published. Required fields are marked *