Reputation: 761
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.
Upvotes: 0
Views: 992
Reputation: 197777
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.
Upvotes: 1
Reputation: 592
The MySQL TEXT field can only hold 64k of data; once you pass that it will truncate your serialized data. If you need more space you should change the field type to MEDIUMTEXT which can hold up to 16MB or LONGTEXT which can store up to 4GB.
Upvotes: 1
Reputation: 7249
Most likely the SQL table, maybe use a larger field. http://help.scibit.com/mascon/masconMySQL_Field_Types.html These will show the sizes of each field. If you are storing a lot, use a blob which basically stores a file.
If it is only temp data, then no need to store it in the database if it will only get deleted later.
Upvotes: 0