I have a simple try catch which is not operating how I would expect. This is my first try at using transactions with PDO:
try
{
$dbo = Db::init();
$dbo->beginTransaction();
$dbo->exec("TRUNCATE TABLE {$this->table}");
$dbo->exec($insert);
$dbo->commit();
}
catch(Exception $e)
{
$dbo->rollBack();
echo 'Failed to sync ' . $this->table;
}
The problem is, if the $dbo->exec($insert);
fails, the $dbo->exec("TRUNCATE TABLE {$this->table}");
does not get rolled back. Any ideas?
TRUNCATE
cannot be rolled back. Use DELETE
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With