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:
@@ -332,6 +332,32 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
|||||||
return $this->pdo()->inTransaction();
|
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
|
* Commits a transaction
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user