1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-23 14:56:51 +02:00

Add $database->supportsTransaction($table = '') method to return true or false as to whether the database (or a specific table) supports transactions

This commit is contained in:
Ryan Cramer
2018-09-21 13:30:57 -04:00
parent 9a7e5d5bd3
commit b4aec46a67

View File

@@ -332,6 +332,32 @@ class WireDatabasePDO extends Wire implements WireDatabase {
return $this->pdo()->inTransaction();
}
/**
* Are transactions available with current DB engine (or table)?
*
* #pw-group-PDO
*
* @param string $table Optionally specify a table to specifically check to that table
* @return bool
*
*/
public function supportsTransaction($table = '') {
$engine = '';
if($table) {
$query = $this->prepare('SHOW TABLE STATUS WHERE name=:name');
$query->bindValue(':name', $table);
$query->execute();
if($query->rowCount()) {
$row = $query->fetch(\PDO::FETCH_ASSOC);
$engine = empty($row['engine']) ? '' : $row['engine'];
}
$query->closeCursor();
} else {
$engine = $this->wire('config')->dbEngine;
}
return strtoupper($engine) === 'INNODB';
}
/**
* Commits a transaction
*