I am setting up a website which stores a large (serialized) array of arrays specific to each user. The large array is serialized and then the database is updated to its new value. Also, the new array is added to the $_SESSION[] array which is used for the period the user is logged in. I can UPDATE the array fine with up to 4 of these arrays in the large array but after that the data does not seem to UPDATE properly.
The MySQL UPDATE query returns 1 even after the 3rd array has been added and the $_SESSION[] array seems to contain all the right data but when the user logs out and then back in again, the array does not seem to be copied to the $_SESSION[] array as it should whenever the user logs in. If only 4 of these arrays are stored in the large array, the data can be fetched from the database no problem. I increased the length of the database field beyond what would be required (and then increased it faaaar beyond what should be required) but it did not help.
When I go to phpMyAdmin, I can see that the array is updated successfully until after array 3 when the serialised array stops abruptly (in the middle of a sentence in the serialised array) but I think this might be an issue with phpMyAdmin because alongside the array edit box it says ‘Because of its length, this field might not be editable’ so maybe phpMyAdmin is just not bothering to load the rest of the array into the tiny textarea.
Is there anything I can do to fix this issue? Is there anything I may not be aware of (I am a beginner with MySQL but it seems to have been working okay up until now).
The code used to update the database is like this:
$_SESSION['data']['user']['templates'][$_SESSION['edit']['templateNo']] = $template;
$serializedTemplates = mysql_real_escape_string(serialize($_SESSION['data']['user']['templates']));
$serializedReports = mysql_real_escape_string(serialize($_SESSION['data']['user']['reports']));
$email = mysql_real_escape_string($_SESSION['data']['user']['details']['email']);
$returned = mysql_query("UPDATE rmusers SET templates='$serializedTemplates', reports='$serializedReports' WHERE email='$email'") or die (mysql_error());
The ‘reports’ and ’email’ array elements are not really relevant.
The code used to retrieve the array from the database is like this:
$result = mysql_query("SELECT * FROM rmusers WHERE email='" . $_POST['email'] ."'");
$userRow = mysql_fetch_array($result);
if (strlen(unserialize($userRow['templates'])) > 0)
{
$_SESSION['data']['user']['templates'] = unserialize($userRow['templates']);
}
Also, sorry I have used the word ‘array’ about 25 times in the above question 🙂
Your field type is
text, which has a maximum length of 65535 characters. Switch over tolongtext, that has a theoretical limit of 4GB. However keep in mind that the docs says:Also see the documentation of the max_allowed_packet setting: