I'm using Mysql and PHP with PDO and all my tables are InnoDB. Does beginTransaction improve performance of multiple UPDATE?
For example, is the first example below better than second in terms of performance?
First example:
<?php
$dbh = new PDO($dsn, $user, $password);
$dbh->beginTransaction();
$sql = 'UPDATE test_commit SET ad=:ad WHERE id=1';
$sth = $dbh->prepare($sql);
$sth->execute(array(':ad' => 10));
$sql = 'UPDATE test_commit SET ad=:ad WHERE id=2';
$sth = $dbh->prepare($sql);
$sth->execute(array(':ad' => 11));
$dbh->commit();
Second example:
<?php
$dbh = new PDO($dsn, $user, $password);
$sql = 'UPDATE test_commit SET ad=:ad WHERE id=1';
$sth = $dbh->prepare($sql);
$sth->execute(array(':ad' => 10));
$sql = 'UPDATE test_commit SET ad=:ad WHERE id=2';
$sth = $dbh->prepare($sql);
$sth->execute(array(':ad' => 11));
The second question is, if instead of two update I had made two inserts in the two examples, what would be in terms of performance the better example?