为什么不将序列化的数组插入数据库字段? [英] Why should I not insert serialized arrays into my database field?

查看:79
本文介绍了为什么不将序列化的数组插入数据库字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚看到对此问题的第一条评论插入到序列化数组中PHP ,这让我想知道为什么吗?特别是看到使用数据库管理的会话(基于数据库的会话处理)时,会话处理程序将序列化的数组插入数据库字段中.

I just saw the first comment to this question Inserting into a serialized array in PHP and it made me wonder why? Especially seeing that when you use database managed sessions (database based session handling) that is exactly what happens, the session handler inserts a serialized array into a database field.

推荐答案

在某些情况下,这没有错.会话管理绝对是可以接受的实例之一.要记住的事情是,如果您发现自己试图在序列化数据和数据库中的任何字段之间关联数据,那么您就犯了一个巨大的设计缺陷,不幸的是,这是我看到的人们试图做的事情.

There's nothing wrong with this in certain contexts. Session management is definitely one of those instances where this would be deemed acceptable. The thing to remember is that if you ever find yourself trying to relate data between the serialized data and any fields in your database you've made a huge design flaw and unfortunately this is something that I have seen people try to do.

将任何永不做x"都与一粒盐一起服用,因为在某些情况下几乎任何技术都是正确的方法.该建议通常针对那些很容易误解正确用法并将自己编码到一个非常讨厌的角落的菜鸟.

Take any "never do x" with a grain of salt as almost any technique can be the correct one in certain circumstances. The advice is usually directed towards noobies who are very apt to misunderstand proper usage and code themselves into a very nasty corner.

这篇关于为什么不将序列化的数组插入数据库字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆