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 30, 2022
1 parent 01c27e6 commit 3a0fff2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 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,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()
Expand Down

0 comments on commit 3a0fff2

Please sign in to comment.