Является ли хорошей практикой использование сериализации в PHP для хранения данных в БД?

Я наткнулся на интересный комментарий вphp.net о сериализации данных, чтобы сохранить их в БД.

Это говорит следующее:

Please! please! please! DO NOT serialize data and place it into your database. Serialize can be used that way, but that's missing the point of a relational database and the datatypes inherent in your database engine. Doing this makes data in your database non-portable, difficult to read, and can complicate queries. If you want your application to be portable to other languages, like let's say you find that you want to use Java for some portion of your app that it makes sense to use Java in, serialization will become a pain in the buttocks. You should always be able to query and modify data in the database without using a third party intermediary tool to manipulate data to be inserted.

I've encountered this too many times in my career, it makes for difficult to maintain code, code with portability issues, and data that is it more difficult to migrate to other RDMS systems, new schema, etc. It also has the added disadvantage of making it messy to search your database based on one of the fields that you've serialized.

That's not to say serialize() is useless. It's not... A good place to use it may be a cache file that contains the result of a data intensive operation, for instance. There are tons of others... Just don't abuse serialize because the next guy who comes along will have a maintenance or migration nightmare.

Я хотел бы знать, является ли это стандартным представлением об использовании сериализации данных для целей БД. Это означает, что это хорошая практика - иногда использовать его или его следует избегать.

Например, мне недавно дали указание использовать сериализацию.

В этом случае данные, которые мы должны были сохранить в таблицу MySQL, были следующими:

Car brand. Car model. Car version. Car info.

Информация о машине представляла собой массив, представляющий все свойства версии, так что это было большое количество переменных (менее 100 свойств). Этот массив был сериализованным.

Основной причиной, по которой мне дали сериализацию, было следующее:

Being a large number of fields, it is better to serialize the data in order to improve performance instead of creating a field for each property or multiple tables.

Лично я больше согласен с комментариями в php.net, чем с этой последней сборкой, но я хотел бы привести здесь более квалифицированные мнения, чем мои, по этому поводу.

Ответы на вопрос(1)

Ваш ответ на вопрос