Omit beginTransaction commit PDO MYSQL

Asked

Viewed 64 times

0

What happens in practice when I omit the begin transaction and the commit in a PHP script using PDO?

I have a loading script, which processes school data, every school that finishes processing I do a insert. This code below is inside a loop that runs through a gigantic list of schools.
In that case I did not insert the begintran and the commit. He commits self after each insertion?

$insere = $pdo->prepare("Insert INTO `tabela`(campo1,campo2,campo3) VALUES (:valor1,:valor2,:valor3)");
        $insere->bindValue(":valor1", $dado1);
        $insere->bindValue(":valor2", $dado2);
        $insere->bindValue(":valor3", $dado3);
        $insere->execute();

1 answer

0

Yes

In the case of databases that follow the ACID model, in the absence of transactions then each instruction ends up having an automatic implicit transaction. Basically is autocommit at every instruction. And Mysql follows this model.

In this particular case be prepared to deal with failures. If there is an error in processing this "gigantic" list, then a new round of script might not work (Inserts fail by primary key duplication).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.