diff --git a/src/ORM/Connect/PDOConnector.php b/src/ORM/Connect/PDOConnector.php index 4a5c81f018e..7f4c5ff3e08 100644 --- a/src/ORM/Connect/PDOConnector.php +++ b/src/ORM/Connect/PDOConnector.php @@ -7,6 +7,7 @@ use PDO; use PDOStatement; use InvalidArgumentException; +use PDOException; /** * PDO driver database connector @@ -109,10 +110,15 @@ public function getOrPrepareStatement($sql) } // Generate new statement - $statement = $this->pdoConnection->prepare( - $sql, - [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY] - ); + try { + $statement = $this->pdoConnection->prepare( + $sql, + [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY] + ); + } catch (PDOException $e) { + $statement = false; + $this->databaseError($e->getMessage(), E_USER_ERROR, $sql); + } // Wrap in a PDOStatementHandle, to cache column metadata $statementHandle = ($statement === false) ? false : new PDOStatementHandle($statement); @@ -557,8 +563,13 @@ public function transactionRollback($savepoint = null) } } + // Note: $this->inTransaction may not match the 'in-transaction' state in PDO $this->inTransaction = false; - return $this->pdoConnection->rollBack(); + if ($this->pdoConnection->inTransaction()) { + return $this->pdoConnection->rollBack(); + } + // return false because it did not rollback. + return false; } public function transactionDepth()