I have a database of 100,000 contacts.
I have a multiple select box which I would like to use to select contacts to add to a specific mailing list.
My problem is that I am currently storing the data for the mailing list in a serialized array format (PHP) in MySQL.
When I select over a certain number of contacts, something seems to break (I assume not enough memory) and does not update the array.
Is there a best way to store a large array in MySQL and is there a best way to keep memory usage in a PHP array()
low?
Code Example
if(isset($_POST['add'])) {
$name = $core->EscapeString($_POST['name']);
$desc = $core->EscapeString($_POST['desc']);
foreach($_POST['addSelect'] as $null => $id) {
if(!in_array($id, $recipientArray)) {
$recipientArray[] = $id;
}
}
$contacts->updateML($lid, $name, $desc, serialize($recipientArray));
}
else if(isset($_POST['rm'])) {
$name = $core->EscapeString($_POST['name']);
$desc = $core->EscapeString($_POST['desc']);
foreach($recipientArray as $null => $id) {
foreach($_POST['rmSelect'] as $null1 => $id1) {
if($id == $id1) {
unset($recipientArray[$null]);
}
}
}
$contacts->updateML($lid, $name, $desc, serialize($recipientArray));
}
UpdateML Function
//Class 3, Function 16
function updateML($lid = '', $name = '', $desc = '', $recip = '') {
global $MySQLi;
$query = "UPDATE `mailing_lists` SET `name` = '".$name."', `desc` = '".$desc."', `recipients` = '".$recip."' WHERE `list_id` = '".$lid."' LIMIT 1";
$commit = $MySQLi->query($query);
if($commit == false) {
die("Issues with the database were detected. Please email peter@domain.com quoting error code: <strong>CLASS3/16.1</strong>.");
}
else
{
return true;
}
}