| @@ 654-685 (lines=32) @@ | ||
| 651 | * @return bool |
|
| 652 | * <p>This will return true or false indicating success of transaction</p> |
|
| 653 | */ |
|
| 654 | public function beginTransaction(): bool |
|
| 655 | { |
|
| 656 | if ($this->in_transaction) { |
|
| 657 | $this->debug->displayError('Error: mysql server already in transaction!', false); |
|
| 658 | ||
| 659 | return false; |
|
| 660 | } |
|
| 661 | ||
| 662 | $this->clearErrors(); // needed for "$this->endTransaction()" |
|
| 663 | $this->in_transaction = true; |
|
| 664 | ||
| 665 | if ($this->mysqli_link) { |
|
| 666 | $return = \mysqli_autocommit($this->mysqli_link, false); |
|
| 667 | } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) { |
|
| 668 | $this->doctrine_connection->setAutoCommit(false); |
|
| 669 | $this->doctrine_connection->beginTransaction(); |
|
| 670 | ||
| 671 | if ($this->doctrine_connection->isTransactionActive()) { |
|
| 672 | $return = true; |
|
| 673 | } else { |
|
| 674 | $return = false; |
|
| 675 | } |
|
| 676 | } else { |
|
| 677 | $return = false; |
|
| 678 | } |
|
| 679 | ||
| 680 | if (!$return) { |
|
| 681 | $this->in_transaction = false; |
|
| 682 | } |
|
| 683 | ||
| 684 | return $return; |
|
| 685 | } |
|
| 686 | ||
| 687 | /** |
|
| 688 | * Clear the errors in "_debug->_errors". |
|
| @@ 748-775 (lines=28) @@ | ||
| 745 | * @return bool |
|
| 746 | * <p>bool true on success, false otherwise.</p> |
|
| 747 | */ |
|
| 748 | public function commit(): bool |
|
| 749 | { |
|
| 750 | if (!$this->in_transaction) { |
|
| 751 | $this->debug->displayError('Error: mysql server is not in transaction!', false); |
|
| 752 | ||
| 753 | return false; |
|
| 754 | } |
|
| 755 | ||
| 756 | if ($this->mysqli_link) { |
|
| 757 | $return = \mysqli_commit($this->mysqli_link); |
|
| 758 | \mysqli_autocommit($this->mysqli_link, true); |
|
| 759 | } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) { |
|
| 760 | $this->doctrine_connection->commit(); |
|
| 761 | $this->doctrine_connection->setAutoCommit(true); |
|
| 762 | ||
| 763 | if ($this->doctrine_connection->isAutoCommit()) { |
|
| 764 | $return = true; |
|
| 765 | } else { |
|
| 766 | $return = false; |
|
| 767 | } |
|
| 768 | } else { |
|
| 769 | $return = false; |
|
| 770 | } |
|
| 771 | ||
| 772 | $this->in_transaction = false; |
|
| 773 | ||
| 774 | return $return; |
|
| 775 | } |
|
| 776 | ||
| 777 | /** |
|
| 778 | * Open a new connection to the MySQL server. |
|
| @@ 2166-2194 (lines=29) @@ | ||
| 2163 | * @return bool |
|
| 2164 | * <p>bool true on success, false otherwise.</p> |
|
| 2165 | */ |
|
| 2166 | public function rollback(): bool |
|
| 2167 | { |
|
| 2168 | if (!$this->in_transaction) { |
|
| 2169 | $this->debug->displayError('Error: mysql server is not in transaction!', false); |
|
| 2170 | ||
| 2171 | return false; |
|
| 2172 | } |
|
| 2173 | ||
| 2174 | // init |
|
| 2175 | $return = false; |
|
| 2176 | ||
| 2177 | if ($this->mysqli_link) { |
|
| 2178 | $return = \mysqli_rollback($this->mysqli_link); |
|
| 2179 | \mysqli_autocommit($this->mysqli_link, true); |
|
| 2180 | } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) { |
|
| 2181 | $this->doctrine_connection->rollBack(); |
|
| 2182 | $this->doctrine_connection->setAutoCommit(true); |
|
| 2183 | ||
| 2184 | if ($this->doctrine_connection->isAutoCommit()) { |
|
| 2185 | $return = true; |
|
| 2186 | } else { |
|
| 2187 | $return = false; |
|
| 2188 | } |
|
| 2189 | } |
|
| 2190 | ||
| 2191 | $this->in_transaction = false; |
|
| 2192 | ||
| 2193 | return $return; |
|
| 2194 | } |
|
| 2195 | ||
| 2196 | /** |
|
| 2197 | * Try to secure a variable, so can you use it in sql-queries. |
|