/** * Cancel any database changes done during the current transaction. * * this method can be listened with onPreTransactionRollback and onTransactionRollback * eventlistener methods * * @throws ConnectionException If the rollback operation failed. */ public function rollBack() { if ($this->_transactionNestingLevel == 0) { throw ConnectionException::noActiveTransaction(); } $this->connect(); $logger = $this->_config->getSQLLogger(); if ($this->_transactionNestingLevel == 1) { if ($logger) { $logger->startQuery('"ROLLBACK"'); } $this->_transactionNestingLevel = 0; $this->_conn->rollback(); $this->_isRollbackOnly = false; if ($logger) { $logger->stopQuery(); } } else { if ($this->_nestTransactionsWithSavepoints) { if ($logger) { $logger->startQuery('"ROLLBACK TO SAVEPOINT"'); } $this->rollbackSavepoint($this->_getNestedTransactionSavePointName()); --$this->_transactionNestingLevel; if ($logger) { $logger->stopQuery(); } } else { $this->_isRollbackOnly = true; --$this->_transactionNestingLevel; } } }
/** * @return \Doctrine\DBAL\Connection * @throws \Doctrine\DBAL\DBALException */ private static function create() { $configuration = new Configuration(); $configuration->getSQLLogger(new EchoSQLLogger()); $parameters = ['dbname' => $_ENV['testsuite_db_name'], 'user' => $_ENV['testsuite_db_user'], 'password' => $_ENV['testsuite_db_password'], 'host' => $_ENV['testsuite_db_host'], 'driver' => 'pdo_mysql']; $connection = DriverManager::getConnection($parameters, $configuration); return $connection; }
/** * Executes an SQL statement, returning a result set as a Statement object. * * @return \Doctrine\DBAL\Driver\Statement * * @throws \Doctrine\DBAL\DBALException */ public function query() { $this->connect(); $args = func_get_args(); $logger = $this->_config->getSQLLogger(); if ($logger) { $logger->startQuery($args[0]); } try { switch (func_num_args()) { case 1: $statement = $this->_conn->query($args[0]); break; case 2: $statement = $this->_conn->query($args[0], $args[1]); break; default: $statement = call_user_func_array(array($this->_conn, 'query'), $args); break; } } catch (\Exception $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $args[0]); } $statement->setFetchMode($this->defaultFetchMode); if ($logger) { $logger->stopQuery(); } return $statement; }