| @@ 643-673 (lines=31) @@ | ||
| 640 | * @return bool |
|
| 641 | * <p>This will return true or false indicating success of transaction</p> |
|
| 642 | */ |
|
| 643 | public function beginTransaction(): bool |
|
| 644 | { |
|
| 645 | if ($this->in_transaction) { |
|
| 646 | $this->debug->displayError('Error: mysql server already in transaction!', false); |
|
| 647 | ||
| 648 | return false; |
|
| 649 | } |
|
| 650 | ||
| 651 | $this->clearErrors(); // needed for "$this->endTransaction()" |
|
| 652 | $this->in_transaction = true; |
|
| 653 | ||
| 654 | if ($this->mysqli_link) { |
|
| 655 | $return = \mysqli_autocommit($this->mysqli_link, false); |
|
| 656 | } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) { |
|
| 657 | $this->doctrine_connection->setAutoCommit(false); |
|
| 658 | ||
| 659 | if ($this->doctrine_connection->isTransactionActive()) { |
|
| 660 | $return = true; |
|
| 661 | } else { |
|
| 662 | $return = false; |
|
| 663 | } |
|
| 664 | } else { |
|
| 665 | $return = false; |
|
| 666 | } |
|
| 667 | ||
| 668 | if (!$return) { |
|
| 669 | $this->in_transaction = false; |
|
| 670 | } |
|
| 671 | ||
| 672 | return $return; |
|
| 673 | } |
|
| 674 | ||
| 675 | /** |
|
| 676 | * Clear the errors in "_debug->_errors". |
|
| @@ 738-765 (lines=28) @@ | ||
| 735 | * @return bool |
|
| 736 | * <p>bool true on success, false otherwise.</p> |
|
| 737 | */ |
|
| 738 | public function commit(): bool |
|
| 739 | { |
|
| 740 | if (!$this->in_transaction) { |
|
| 741 | $this->debug->displayError('Error: mysql server is not in transaction!', false); |
|
| 742 | ||
| 743 | return false; |
|
| 744 | } |
|
| 745 | ||
| 746 | if ($this->mysqli_link) { |
|
| 747 | $return = \mysqli_commit($this->mysqli_link); |
|
| 748 | \mysqli_autocommit($this->mysqli_link, true); |
|
| 749 | } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) { |
|
| 750 | $this->doctrine_connection->commit(); |
|
| 751 | $this->doctrine_connection->setAutoCommit(true); |
|
| 752 | ||
| 753 | if ($this->doctrine_connection->isAutoCommit()) { |
|
| 754 | $return = true; |
|
| 755 | } else { |
|
| 756 | $return = false; |
|
| 757 | } |
|
| 758 | } else { |
|
| 759 | $return = false; |
|
| 760 | } |
|
| 761 | ||
| 762 | $this->in_transaction = false; |
|
| 763 | ||
| 764 | return $return; |
|
| 765 | } |
|
| 766 | ||
| 767 | /** |
|
| 768 | * Open a new connection to the MySQL server. |
|
| @@ 2232-2260 (lines=29) @@ | ||
| 2229 | * @return bool |
|
| 2230 | * <p>bool true on success, false otherwise.</p> |
|
| 2231 | */ |
|
| 2232 | public function rollback(): bool |
|
| 2233 | { |
|
| 2234 | if (!$this->in_transaction) { |
|
| 2235 | $this->debug->displayError('Error: mysql server is not in transaction!', false); |
|
| 2236 | ||
| 2237 | return false; |
|
| 2238 | } |
|
| 2239 | ||
| 2240 | // init |
|
| 2241 | $return = false; |
|
| 2242 | ||
| 2243 | if ($this->mysqli_link) { |
|
| 2244 | $return = \mysqli_rollback($this->mysqli_link); |
|
| 2245 | \mysqli_autocommit($this->mysqli_link, true); |
|
| 2246 | } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) { |
|
| 2247 | $this->doctrine_connection->rollBack(); |
|
| 2248 | $this->doctrine_connection->setAutoCommit(true); |
|
| 2249 | ||
| 2250 | if ($this->doctrine_connection->isAutoCommit()) { |
|
| 2251 | $return = true; |
|
| 2252 | } else { |
|
| 2253 | $return = false; |
|
| 2254 | } |
|
| 2255 | } |
|
| 2256 | ||
| 2257 | $this->in_transaction = false; |
|
| 2258 | ||
| 2259 | return $return; |
|
| 2260 | } |
|
| 2261 | ||
| 2262 | /** |
|
| 2263 | * Try to secure a variable, so can you use it in sql-queries. |
|