php 序列化存入数据库被截断,为了将数据存储到数据库中,在PHP中使用序列化是一种好习惯吗?...

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值