Good morning, I am faced with the problem that because of the size of the query, it is impossible for me to execute it, and it is not feasible to cut it into very small pieces because it would never end. I'm using the Laravel 5.5 framework, but even so I decided not to use Eloquent for performance.
What I really need is to update one column with the value of another but passing it html_entity_decode()
$main_query_sql = "SELECT id, Body FROM emails WHERE mensaje IS NULL";
$main_query = $db->prepare($main_query_sql);
$main_query->execute();
$query_sql = null;
while ($email = $main_query->fetch()) {
$query_sql = "UPDATE emails SET mensaje = :mensaje WHERE id = :id";
$query_sql = $db->prepare($query_sql);
$query_sql->bindParam(':mensaje', html_entity_decode($email['Body']));
$query_sql->bindParam(':id', $email['id']);
$query_sql->execute();
All this is also in a transaction, but it does not get to enter the while.
I have changed the parameters of mysql and apache to have no limits, both in file and execution time and still gives me a PHP Fatal error: Out of memory (allocated 1853882368) (tried to allocate 32768 bytes)
in a server dedicated to this only with more than enough requirements.
ini_set ('memory_limit', '-1'); ini_set ('max_execution_time', 0); DB :: disableQueryLog (); \ Debugbar :: disable ();
PS: in case somebody is worth to understand what he had before
Email::select('id', 'mensaje', 'Body')->whereNull('mensaje')->chunk(100,
function ($emails) {
$email = null;
foreach ($emails as $email) {
$email->mensaje = html_entity_decode($email->Body);
$email->save();
}
});