1

I have a serialized object stored in a mysql database in a column of type text saved via php.

If I double click the field in PHPMyAdmin to edit the value of the field inline, and then save the edit by clicking away from the edit box, the serialized data in the field is rendered corrupt somehow.

I get the following PHP error after doing this:

Notice: unserialize(): Error at offset 913 of 1951 bytes in /path/to/file.php on line 46

I am not even changing any of the data, as I am only clicking in to copy the data to the clipboard so it's not as though I'm introducing anything weird, or making an error with the syntax etc. I thought maybe some whitespace is getting added or some wierd character(s).

Is there a solution to this?

Marc
  • 746
  • 1
  • 12
  • 28
  • Does the error really say `/path/to/file.php` or is there a real filename there? Can you show an example uncorrupted row? I've tried with some simple data and haven't any trouble, is there a chance your data is exceeding the storage limitations for your column definition? What phpMyAdmin version? – Isaac Bennetch Nov 21 '15 at 02:59

2 Answers2

1

According to this question, in order to avoid errors you can try to base64 the output or serialize() before inserting it into the database:

$toDatabse = base64_encode(serialize($data));  // Save to database
$fromDatabase = unserialize(base64_decode($data)); //Getting Save Format 
Community
  • 1
  • 1
Phate01
  • 2,499
  • 2
  • 30
  • 55
1

There is a bug in phpmyadmin that saves the '\n' of a serialized php string as line breaks. PHP serialized strings must not contain line breaks! If you want to safely modify it directly from phpmyadmin, make sure to replace the line breaks with '\n' string, this can easily be done from any text editor.

JorgeMora
  • 21
  • 2