Skip to content

Commit

Permalink
FIX PDO in PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 29, 2022
1 parent 01c27e6 commit da75ce6
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/ORM/Connect/PDOConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PDO;
use PDOStatement;
use InvalidArgumentException;
use PDOException;

/**
* PDO driver database connector
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -557,8 +563,11 @@ 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()) {
$this->pdoConnection->rollBack();
}
}

public function transactionDepth()
Expand Down

0 comments on commit da75ce6

Please sign in to comment.