Doubt with column Bank

Asked

Viewed 27 times

0

I received a mysql dump for study and I was doubtful in a certain text column with the fields filled in this way:

'a:5:{
    s:9:\"user_data\";
    s:0:\"\";
    s:4:\"nome\";
    s:5:\"admin\";
    s:2:\"id\";
    s:1:\"1\";
    s:9:\"permissao\";
    s:1:\"1\";
    s:6:\"logado\";
    b:1;
}'

the yes column contained that name user_data . They could help me with this knowledge doubt. Unfortunately I don’t have the system code. In another table tbm contains a column like this but with column name permissions.

1 answer

1


This data format is generated by serialize php, it is used to convert php variables and a format that can be stored, mainly arrays.

When you do this:

<?php
$data = array(
   'nome' => 'Thalles',
   'hobby' => 'Programar'
);

echo serialize($data);

Is generated this string:

a:2:{s:4:"nome";s:7:"Thalles";s:5:"hobby";s:9:"Programar";}

Then you can store in a database or . txt and recover it later, however it will be necessary to use the unserialize to decode, for example:

save php.

<?php
$data = array(
   'nome' => 'Thalles',
   'hobby' => 'Programar'
);

file_put_contents('data.txt', serialize($data));

read php.

<?php
$data = unserialize(file_get_contents('data.txt'));//Trás de volta o array

print_r($data);

This way you can store several data in a column only in your database, wordpress uses this technique to facilitate custom creation of plugins and banners.

  • 1

    Thank you so much for the information. Adding serialize in the studies :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.