I have a table with 700,000 entries and I need to check each entry for 1,000,000 words and then replace the word if found from hello
to #~hello~#
. Words can occur multiple times in an entry and need to all be replaced. I tried this in PHP and the estimated time was something like 362 days to complete the code. I just modified the code to use a LIKE in MySQL so that I didn't have check each of the 1,000,000 words against all 700,000 entries, but the estimated time for completion is still 29 days. This seems really high.
Further complicating the matter words can be multiple words. For example if the word is hello world
the program should replace with #~hello world~#
.
What am I missing?
The code looks something like this:
$query = "SELECT word_id, word_name, FROM words ORDER BY char_length(word_name) DESC";
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_array($result)){
$words[$i] = new wordObj($row['word_id'], $row['word_name']);
}
Foreach($words as $word){
$query = "SELECT id, entry FROM entries WHERE entry LIKE '%".$word."%'";
$result = mysqli_query($con, $query);
if ($result) {
if ($result->num_rows != 0) {
while($row = mysqli_fetch_array($result)){
$entry[$i] = new meatObj($row['id'], $row['entry']);
$i++;
}
}else{
$entry = '';
}
}else{
$entry ='';
}
foreach($entryArray as $entry){
check entry for all words and replace
}
}