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条)

报告相同问题?

悬赏问题

  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导