In PHP you can start transactions when you are performing queries. But when should you use it? Is it bad to use this feature with every query? Or should you only use this query when you are adding/removing/updating large quantities of data?
Example of a transaction:
try {
$db->beginTransaction();
$db->exec("some query");
$stmt = $db->prepare("another query");
$stmt->execute(array($value));
$stmt = $db->prepare("another query again??");
$stmt->execute(array($value2, $value3));
$db->commit();
} catch(PDOException $ex) {
//Something went wrong rollback!
$db->rollBack();
echo $ex->getMessage();
}
My guess would be that it would heavily bring down performance if you do this with every query in your code
tl;dr Can you use transactions with every query? Or should you only use them when performing large manipulations to the database?