Permalink
Browse files

Add $database->supportsTransaction($table = '') method to return true…

… or false as to whether the database (or a specific table) supports transactions
  • Loading branch information...
ryancramerdesign committed Sep 21, 2018
1 parent 9a7e5d5 commit b4aec46a67f7521a0bb8933bf0fb48ae5b9c8303
Showing with 26 additions and 0 deletions.
  1. +26 −0 wire/core/WireDatabasePDO.php
@@ -332,6 +332,32 @@ public function 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
*

0 comments on commit b4aec46

Please sign in to comment.