* [refac] Check if is in transaction before rollback or commit in dbh class.

This commit is contained in:
liugang
2025-12-30 15:59:41 +08:00
parent 497576098e
commit 61ce4ff931
2 changed files with 13 additions and 13 deletions
+10 -10
View File
@@ -492,11 +492,11 @@ class baseDAO
* Begin Transaction
*
* @access public
* @return void
* @return bool
*/
public function begin()
public function begin(): bool
{
if(!$this->dbh->inTransaction()) $this->dbh->beginTransaction();
return $this->dbh->beginTransaction();
}
/**
@@ -506,7 +506,7 @@ class baseDAO
* @access public
* @return bool
*/
public function inTransaction()
public function inTransaction(): bool
{
return $this->dbh->inTransaction();
}
@@ -516,11 +516,11 @@ class baseDAO
* Roll back
*
* @access public
* @return void
* @return bool
*/
public function rollBack()
public function rollBack(): bool
{
if($this->dbh->inTransaction()) $this->dbh->rollBack();
return $this->dbh->rollBack();
}
/**
@@ -528,11 +528,11 @@ class baseDAO
* Commits a transaction.
*
* @access public
* @return void
* @return bool
*/
public function commit()
public function commit(): bool
{
if($this->dbh->inTransaction()) $this->dbh->commit();
return $this->dbh->commit();
}
/**
+3 -3
View File
@@ -1059,7 +1059,7 @@ class dbh
*/
public function beginTransaction()
{
return $this->pdo->beginTransaction();
return $this->pdo->inTransaction() ? false : $this->pdo->beginTransaction();
}
/**
@@ -1081,7 +1081,7 @@ class dbh
*/
public function rollBack()
{
return $this->pdo->rollBack();
return $this->pdo->inTransaction() ? $this->pdo->rollBack() : false;
}
/**
@@ -1092,7 +1092,7 @@ class dbh
*/
public function commit()
{
return $this->pdo->commit();
return $this->pdo->inTransaction() ? $this->pdo->commit() : false;
}
/**