douyan8413 2011-12-19 20:49
浏览 88
已采纳

在写入截断我的数据的mysql后,PHP反序列化错误

I am building an associative array of information and then adding it to a history array by doing $histarray[] = $histrec;

I am then writing the $histarray to mysql by doing serialize($histarray). I defined the field that I am writing to as a text field. The unserialize command quit working when the variable got quit large, > 64k and when I looked, the data is getting truncated. I rewrote my functionality to serialize and write the $histarray to a folder and then read it and unserialize it. This does not cause the same problem and works well.

I have 2 questions.

  1. I assume that the mysql database or the php write to it is truncating the serialized data, but what specifically is causing this? I thought a field that was defined as text was basically unlimited in size.
  2. Is it faster to just read and write a file to a folder in this situation rather than store this info in a MYSQL table. It is only temp session data and does not need to be stored.
  • 写回答

3条回答 默认 最新

  • dousi2553 2011-12-19 21:00
    关注

    1. I assume that the mysql database or the php write to it is truncating the serialized data, but what specifically is causing this? I thought a field that was defined as text was basically unlimited in size.

    Strings in PHP are generally not limited in size (theoretically, factually there is always a limit on something). But really, strings in PHP can be really large. The PHP string limit is not a problem here.

    A field in the database however has a size limit. You might want to use a BLOLB type field for large data, or a LONGBLOB or however it is called in MySQL: http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html

    MySQL truncates when the field can't take all (instead of not updating/inserting).

    2. Is it faster to just read and write a file to a folder in this situation rather than store this info in a MYSQL table. It is only temp session data and does not need to be stored.

    If you don't need to store at all, fastest is to not store: Not in the db nor in the filesystem.

    If you actually need to store, it depends what is faster on your system configuration. Both can be pretty fast, database and file-system.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c