Merge pull request #10385 from silverstripe/pulls/4.10/pdo

FIX PDO in PHP 8
This commit is contained in:
Guy Sartorelli 2022-07-04 18:24:10 +12:00 committed by GitHub
commit 8a314a90e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ use SilverStripe\Dev\Deprecation;
use PDO; use PDO;
use PDOStatement; use PDOStatement;
use InvalidArgumentException; use InvalidArgumentException;
use PDOException;
/** /**
* PDO driver database connector * PDO driver database connector
@ -109,10 +110,15 @@ class PDOConnector extends DBConnector implements TransactionManager
} }
// Generate new statement // Generate new statement
$statement = $this->pdoConnection->prepare( try {
$sql, $statement = $this->pdoConnection->prepare(
[PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY] $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 // Wrap in a PDOStatementHandle, to cache column metadata
$statementHandle = ($statement === false) ? false : new PDOStatementHandle($statement); $statementHandle = ($statement === false) ? false : new PDOStatementHandle($statement);
@ -557,8 +563,13 @@ class PDOConnector extends DBConnector implements TransactionManager
} }
} }
// Note: $this->inTransaction may not match the 'in-transaction' state in PDO
$this->inTransaction = false; $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() public function transactionDepth()