How best to store an array in a single field in the database

Asked

Viewed 249 times

1

Is usually used implode/explode or serialize/unserialize to store multiple information of a particular item in the database. Using PDO, which would be the best and whether there is another way to store an array in a single database field?

  • 4

    It is generally not recommended to create multi-valued columns :P if you really need to and are using Mysql version 5.7 you can create a json-like column.

  • @rray, in short, is it right to create a JSON type field in the database? So, how would you store such data using PDO? I use PDO::PARAM_STR?

  • 1

    The ideal is to normalize their tables, for example would need a table for news another for categories and an associative to tie a news to several categories. If it is not possible to create a json column, for PDO you can pass as string (PDO::PARAM_STR) even.

No answers

Browser other questions tagged

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