I am saving data in a mysql database. This data is an array and the content is different data of the current user that is logged in to my system.
I do this when I save to the database:
$data = addslashes(serialize($array));
then
"UPDATE or INSERT INTO TABLE SET ... data = '$data';"
Now, the data are saved correctly since the insert or update statement return valid from my php code.
My problem is when I try to un-serialize it, it returns false and a notice is shown in my page.
What am I doing wrong?
I will bet the field in your mysql database is not big enough to save all the characters. That is why, when you un-serialize it you get an notice and nothing in return.
Try to increase the field to a MEDIUMBLOB
or MEDIUMTEXT
(maximum length of 16,777,215) or LONGBLOB
or LONGTEXT
(maximum length of 4,294,967,295) like this:
ALTER TABLE your_table MODIFY COLUMN column_name MEDIUMTEXT /* other properties*/;
And try to save and read your data again.
Now, if your data is over 4,294,967,295 (which is LONGBLOB or LONGTEXT), maybe you should check what kind of data you saving and maybe filter or remove unwanted some.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With