Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

php - What is the type this string? a:1:{s:2:"en";}

a:1:{s:2:"en";s:39:"Sample Text";}

Shortly my question, do you have an idea about the above format?

I want to store long site settings following array like above format like JSON.

$settings = array(
            'slug' => 'test',
            'title' => 'John Doe',
            'description' => 'A Yes or No option for the module',
            '`default`' => '1',
            '`value`' => '1',
            'type' => 'select',
            '`options`' => '1=Yes|0=No',
            'is_required' => 1,
            'is_gui' => 1,
            'module' => 'johndoe'
        );

It look likes JSON but probably it's not.

I have not any idea about this format reading and creating.

In fact which PHP and MySQL Datatype to use for storing long params with best performance?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The datatype you're showing us here is a serialized variable in PHP.

To serialize or unserialize it, just use these two methods :

http://php.net/manual/en/function.serialize.php

http://www.php.net/manual/en/function.unserialize.php

To store it in MySQL, depends on the size of the serialized data. VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT or BIGTEXT are available.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...