Unserialize through query at database level itself

后端 未结 8 525
清酒与你
清酒与你 2020-12-02 12:53

I have a column value stored in the database as:

a:2:{i:0;s:2:\"US\";i:1;s:2:\"19\";}

I want to unserialize it during the mysql

8条回答
  •  [愿得一人]
    2020-12-02 13:46

    It's a very bad practice to add programming language dependent structures to database. If you do so, you always have to rely on that language.

    The best approach is to have normalized table structure (different fields or tables).

    The next approach is to save data as a delimited string (e.g.: 0,US,1,19). Then you can use MySQL's SUBSTRING() or to use standard serialization mechanisms like JSON encode.

提交回复
热议问题