diff --git a/.tests/tests/MigrateTest.php b/.tests/tests/MigrateTest.php
index 9873d56..ebf38dd 100644
--- a/.tests/tests/MigrateTest.php
+++ b/.tests/tests/MigrateTest.php
@@ -129,9 +129,14 @@ class MigrateTest extends UloggerDatabaseTestCase {
foreach ($queries[0] as $query) {
uDb::getInstance()->exec($query);
}
- uDb::getInstance()->commit();
+ // make sure the transaction wasn't autocommitted
+ if (uDb::getInstance()->inTransaction()) {
+ uDb::getInstance()->commit();
+ }
} catch (PDOException $e) {
- uDb::getInstance()->rollBack();
+ if (uDb::getInstance()->inTransaction()) {
+ uDb::getInstance()->rollBack();
+ }
throw $e;
}
}
diff --git a/scripts/migrate_to_1_x.php b/scripts/migrate_to_1_x.php
index 9f722cc..c888419 100644
--- a/scripts/migrate_to_1_x.php
+++ b/scripts/migrate_to_1_x.php
@@ -89,11 +89,16 @@ function updateSchemas() {
foreach ($queries as $query) {
uDb::getInstance()->exec($query);
}
- uDb::getInstance()->commit();
+ // make sure the transaction wasn't autocommitted
+ if (uDb::getInstance()->inTransaction()) {
+ uDb::getInstance()->commit();
+ }
} catch (PDOException $e) {
echo "Database query failed: {$e->getMessage()}" . PHP_EOL;
- echo "Reverting changes..." . PHP_EOL;
- uDb::getInstance()->rollBack();
+ if (uDb::getInstance()->inTransaction()) {
+ echo "Reverting changes..." . PHP_EOL;
+ uDb::getInstance()->rollBack();
+ }
return false;
}
echo PHP_EOL;
diff --git a/scripts/setup.php b/scripts/setup.php
index ff39582..224e11c 100644
--- a/scripts/setup.php
+++ b/scripts/setup.php
@@ -96,9 +96,14 @@ switch ($command) {
foreach ($queries as $query) {
$pdo->exec($query);
}
- $pdo->commit();
+ // MySQL autocommits queries that change schema
+ if ($pdo->inTransaction()) {
+ $pdo->commit();
+ }
} catch (PDOException $e) {
- $pdo->rollBack();
+ if ($pdo->inTransaction()) {
+ $pdo->rollBack();
+ }
$messages[] = "{$langSetup["dbqueryfailed"]}";
$messages[] = sprintf($langSetup["serversaid"], "" . htmlentities($e->getMessage()) . "");
$error = true;