| @@ 627-658 (lines=32) @@ | ||
| 624 | * @return bool |
|
| 625 | * <p>This will return true or false indicating success of transaction</p> |
|
| 626 | */ |
|
| 627 | public function beginTransaction(): bool |
|
| 628 | { |
|
| 629 | if ($this->in_transaction) { |
|
| 630 | $this->debug->displayError('Error: mysql server already in transaction!', false); |
|
| 631 | ||
| 632 | return false; |
|
| 633 | } |
|
| 634 | ||
| 635 | $this->clearErrors(); // needed for "$this->endTransaction()" |
|
| 636 | $this->in_transaction = true; |
|
| 637 | ||
| 638 | if ($this->mysqli_link) { |
|
| 639 | $return = \mysqli_autocommit($this->mysqli_link, false); |
|
| 640 | } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) { |
|
| 641 | $this->doctrine_connection->setAutoCommit(false); |
|
| 642 | $this->doctrine_connection->beginTransaction(); |
|
| 643 | ||
| 644 | if ($this->doctrine_connection->isTransactionActive()) { |
|
| 645 | $return = true; |
|
| 646 | } else { |
|
| 647 | $return = false; |
|
| 648 | } |
|
| 649 | } else { |
|
| 650 | $return = false; |
|
| 651 | } |
|
| 652 | ||
| 653 | if (!$return) { |
|
| 654 | $this->in_transaction = false; |
|
| 655 | } |
|
| 656 | ||
| 657 | return $return; |
|
| 658 | } |
|
| 659 | ||
| 660 | /** |
|
| 661 | * Clear the errors in "_debug->_errors". |
|
| @@ 721-748 (lines=28) @@ | ||
| 718 | * @return bool |
|
| 719 | * <p>bool true on success, false otherwise.</p> |
|
| 720 | */ |
|
| 721 | public function commit(): bool |
|
| 722 | { |
|
| 723 | if (!$this->in_transaction) { |
|
| 724 | $this->debug->displayError('Error: mysql server is not in transaction!', false); |
|
| 725 | ||
| 726 | return false; |
|
| 727 | } |
|
| 728 | ||
| 729 | if ($this->mysqli_link) { |
|
| 730 | $return = \mysqli_commit($this->mysqli_link); |
|
| 731 | \mysqli_autocommit($this->mysqli_link, true); |
|
| 732 | } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) { |
|
| 733 | $this->doctrine_connection->commit(); |
|
| 734 | $this->doctrine_connection->setAutoCommit(true); |
|
| 735 | ||
| 736 | if ($this->doctrine_connection->isAutoCommit()) { |
|
| 737 | $return = true; |
|
| 738 | } else { |
|
| 739 | $return = false; |
|
| 740 | } |
|
| 741 | } else { |
|
| 742 | $return = false; |
|
| 743 | } |
|
| 744 | ||
| 745 | $this->in_transaction = false; |
|
| 746 | ||
| 747 | return $return; |
|
| 748 | } |
|
| 749 | ||
| 750 | /** |
|
| 751 | * Open a new connection to the MySQL server. |
|
| @@ 2129-2157 (lines=29) @@ | ||
| 2126 | * @return bool |
|
| 2127 | * <p>bool true on success, false otherwise.</p> |
|
| 2128 | */ |
|
| 2129 | public function rollback(): bool |
|
| 2130 | { |
|
| 2131 | if (!$this->in_transaction) { |
|
| 2132 | $this->debug->displayError('Error: mysql server is not in transaction!', false); |
|
| 2133 | ||
| 2134 | return false; |
|
| 2135 | } |
|
| 2136 | ||
| 2137 | // init |
|
| 2138 | $return = false; |
|
| 2139 | ||
| 2140 | if ($this->mysqli_link) { |
|
| 2141 | $return = \mysqli_rollback($this->mysqli_link); |
|
| 2142 | \mysqli_autocommit($this->mysqli_link, true); |
|
| 2143 | } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) { |
|
| 2144 | $this->doctrine_connection->rollBack(); |
|
| 2145 | $this->doctrine_connection->setAutoCommit(true); |
|
| 2146 | ||
| 2147 | if ($this->doctrine_connection->isAutoCommit()) { |
|
| 2148 | $return = true; |
|
| 2149 | } else { |
|
| 2150 | $return = false; |
|
| 2151 | } |
|
| 2152 | } |
|
| 2153 | ||
| 2154 | $this->in_transaction = false; |
|
| 2155 | ||
| 2156 | return $return; |
|
| 2157 | } |
|
| 2158 | ||
| 2159 | /** |
|
| 2160 | * Try to secure a variable, so can you use it in sql-queries. |
|