vendredi 25 septembre 2015

Does Eloquent cache prepared statements?

I have a series of INSERT statements to execute, and I would like to use Laravel's Eloquent to do so:

$mountain = Mountain::find(1);
$dragons = [1, 2, 3, 4];
foreach ($dragons as $id){
    $mountain->dragons()->attach($id);  // Eloquent performs an `INSERT` here
}  

I know that Eloquent uses prepared statements, but will it re-prepare the same query over each iteration, or is it smart enough to cache the prepared INSERT statement on the first iteration, and then simply run ->execute on each subsequent iteration?

From PHP's PDO documentation:

By using a prepared statement the application avoids repeating the analyze/compile/optimize cycle. This means that prepared statements use fewer resources and thus run faster.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire