user8663822 user8663822 - 3 years ago 160
PHP Question

for loop insert query turn into update query in transaction function

i check my query .It insert 1st loop after that insert query turn into update is there anyway how to fix this

$database = New database;
DB::transaction(function () use ($database) {
for ($i=0; $i < 5; $i++) {
database->save();
}
});


here is my transaction picture


Answer Source

Put $database = New database; inside the for statement. Because in each loop you need a new database object to do the insertion. Currently, you make an object, then the first loop does the insertion and the reset of loops will update the same object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download