当前位置: 首页>>代码示例>>PHP>>正文


PHP Connection::beginTransaction方法代码示例

本文整理汇总了PHP中Doctrine\DBAL\Connection::beginTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::beginTransaction方法的具体用法?PHP Connection::beginTransaction怎么用?PHP Connection::beginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\DBAL\Connection的用法示例。


在下文中一共展示了Connection::beginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: requestTransaction

 /**
  * Starts a new transactional block, if none is open, or silently completes, if the transaction
  * is already opened.
  */
 public function requestTransaction()
 {
     if (!$this->inTransaction) {
         $this->conn->beginTransaction();
         $this->inTransaction = true;
     }
 }
开发者ID:zyxist,项目名称:cantiga,代码行数:11,代码来源:Transaction.php

示例2: performBeginTransaction

 protected function performBeginTransaction($identifier = NULL)
 {
     if ($identifier === NULL) {
         return $this->conn->beginTransaction();
     }
     $this->conn->createSavepoint($identifier);
 }
开发者ID:koolkode,项目名称:database,代码行数:7,代码来源:Connection.php

示例3: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     if (!is_file($file)) {
         throw new RuntimeException('File does not exists');
     }
     $verbose = $output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL;
     if (!$verbose) {
         $this->logger->pushHandler(new NullHandler());
     }
     try {
         $this->connection->beginTransaction();
         $result = $this->importService->import(file_get_contents($file));
         $this->connection->commit();
         $output->writeln('Import successful!');
         $output->writeln('The following actions were done:');
         $output->writeln('');
         foreach ($result as $message) {
             $output->writeln('- ' . $message);
         }
     } catch (\Exception $e) {
         $this->connection->rollback();
         $output->writeln('An exception occured during import. No changes are applied to the database.');
         $output->writeln('');
         $output->writeln('Message: ' . $e->getMessage());
         $output->writeln('Trace: ' . $e->getTraceAsString());
     }
     if (!$verbose) {
         $this->logger->popHandler();
     }
 }
开发者ID:apioo,项目名称:fusio-impl,代码行数:31,代码来源:ImportCommand.php

示例4: exportData

 public function exportData($export, $reporter)
 {
     $this->conn->beginTransaction();
     try {
         $lastExportedAt = (int) $export['lastExportedAt'];
         $areas = $this->conn->fetchAll('SELECT a.`id`, a.`name`, t.`id` AS `territoryId`, t.`name` AS `territoryName`, a.`customData`, a.`lastUpdatedAt` ' . 'FROM `' . CoreTables::AREA_TBL . '` a ' . 'INNER JOIN `' . CoreTables::TERRITORY_TBL . '` t ON t.`id` = a.`territoryId` ' . 'WHERE a.`projectId` = :projectId AND a.`statusId` = :statusId', [':projectId' => $export['projectId'], ':statusId' => $export['areaStatusId']]);
         $block = new ExportBlock();
         foreach ($areas as $area) {
             $block->addId($area['id']);
             if ($area['lastUpdatedAt'] > $lastExportedAt) {
                 $area['customData'] = json_decode($area['customData']);
                 $block->addUpdatedId($area['id']);
                 $block->addUpdate($area);
             }
         }
         $event = new ExportEvent($export['projectId'], $export['lastExportedAt'], $reporter);
         $event->addBlock('area', $block);
         $event = $this->eventDispatcher->dispatch(ExportEvents::EXPORT_ONGOING, $event);
         $this->conn->executeQuery('UPDATE `' . ExportTables::DATA_EXPORT_TBL . '` SET `lastExportedAt` = :time WHERE `id` = :id', [':time' => time(), ':id' => $export['id']]);
         $this->conn->commit();
         return $event->output();
     } catch (Exception $ex) {
         $this->conn->rollBack();
         throw $ex;
     }
 }
开发者ID:zyxist,项目名称:cantiga,代码行数:26,代码来源:ExportEngine.php

示例5: setUp

 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->entityManager = $this->container->getBean("em");
     $this->albumRepository = $this->container->getBean("albumRepository");
     $this->connection = $this->entityManager->getConnection();
     $this->connection->beginTransaction();
 }
开发者ID:rigobertbot,项目名称:meta-player,代码行数:12,代码来源:AlbumTest.php

示例6: save

 /**
  * Persists task
  *
  * @param Task $task
  * @return Task
  */
 public function save(Task $task)
 {
     $this->connection->beginTransaction();
     $this->_em->persist($task);
     $this->_em->flush();
     $this->_em->commit();
     return $task;
 }
开发者ID:klinki,项目名称:timer,代码行数:14,代码来源:TaskRepository.php

示例7: push

 public function push(array $list)
 {
     $this->create();
     $this->connection->beginTransaction();
     $statement = $this->connection->prepare("\n            INSERT INTO `{$this->table}`(`path`)\n            VALUES (:path)\n        ");
     foreach ($list as $path) {
         $statement->execute(compact('path'));
     }
     $this->connection->commit();
 }
开发者ID:Scrapynizer,项目名称:SearchSkillDeveloper,代码行数:10,代码来源:PathProcessRepository.php

示例8: beginTransaction

 /**
  * Begin transaction
  */
 public function beginTransaction()
 {
     if (0 != $this->connection->getTransactionNestingLevel()) {
         throw new \RuntimeException('Transaction already started');
     }
     $this->connection->beginTransaction();
 }
开发者ID:prooph,项目名称:event-store-doctrine-adapter,代码行数:10,代码来源:DoctrineEventStoreAdapter.php

示例9: rollBack

 /**
  * Rolls back the transaction.
  * It makes sure that the connection is in the correct state regardless of what happened before.
  * Correct state means that connection is not rollback only and does not have a transaction nesting level > 0
  *
  * @throws \Exception
  */
 public function rollBack()
 {
     try {
         /**
          * Roll back all the way as this is supposed to be the top level transaction and we want to reset
          * the nesting level
          */
         $transactionNestingLevel = $this->connection->getTransactionNestingLevel();
         for ($i = 0; $i < $transactionNestingLevel - 1; $i++) {
             $this->connection->rollBack();
         }
         $this->connection->rollBack();
     } catch (\Exception $e) {
         $rethrowable = $this->attemptToReconnectPresumedLostConnection($e);
         /**
          * If connection is functional we need to make sure the connection is not rollback only.
          * This can only be achieved by starting a transaction and rolling it back (the "why" is found in
          * lines 1277-1279 of Doctrine\DBAL\Connection).
          */
         if ($rethrowable === $e) {
             $this->connection->beginTransaction();
             $this->connection->rollBack();
         }
         throw $rethrowable;
     }
 }
开发者ID:phpservicebus,项目名称:persistence-doctrine2,代码行数:33,代码来源:OutboxPersister.php

示例10: massUpsert

 /**
  * Insert multiple rows, if a row with a duplicate key is found will update the row
  * This function assumes that 'id' is the primary key, and is used as a fallback for databases that don't support real upserts
  *
  * @param string $table
  * @param array $rows array of column => value
  * @param null $lastInsertId Optional reference to populate with the last auto increment id
  * @return int The number of affected rows
  *
  * @throws \Doctrine\DBAL\ConnectionException
  * @throws \Exception
  */
 public function massUpsert($table, array $rows, &$lastInsertId = null)
 {
     if (empty($rows)) {
         return 0;
     }
     $rowsToInsert = [];
     $rowsToUpdate = [];
     foreach ($rows as $row) {
         if (!empty($row['id'])) {
             $rowsToUpdate[] = $row;
         } else {
             $rowsToInsert[] = $row;
         }
     }
     $this->db->beginTransaction();
     try {
         $effected = $this->massInsert($table, $rowsToInsert);
         $lastInsertId = $this->getLastInsertId($table) - (count($rowsToInsert) - 1);
         foreach ($rowsToUpdate as $row) {
             $id = $row['id'];
             unset($row['id']);
             $effected += $this->db->update($this->db->quoteIdentifier($table), $this->quoteIdentifiers($row), ['id' => $id]);
         }
         $this->db->commit();
     } catch (\Exception $e) {
         $this->db->rollBack();
         throw $e;
     }
     return $effected;
 }
开发者ID:thewunder,项目名称:corma,代码行数:42,代码来源:QueryHelper.php

示例11: performInitialSetup

 /**
  * @inheritdoc
  */
 public function performInitialSetup()
 {
     $manager = $this->connection->getSchemaManager();
     $from = $manager->createSchema();
     $to = clone $from;
     $table = $to->createTable($this->getQueueTableName());
     $to->createSequence('job_seq');
     $table->addColumn($this->columns[JobReflector::PROPERTY_ID], 'integer', ['autoincrement' => true]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_QUEUE], 'string');
     $table->addColumn($this->columns[JobReflector::PROPERTY_CREATED], 'datetime');
     $table->addColumn($this->columns[JobReflector::PROPERTY_SCHEDULE], 'datetime');
     $table->addColumn($this->columns[JobReflector::PROPERTY_FAILED], 'boolean', ['notnull' => true, 'default' => false]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_FINISHED], 'datetime', ['notnull' => false, 'default' => null]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_RESULT], 'text', ['notnull' => false, 'default' => null]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_PROGRESS], 'decimal', ['notnull' => false, 'default' => null, 'precision' => 5, 'scale' => 2]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_LAST_ATTEMPT], 'datetime', ['notnull' => false, 'default' => null]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_TIMEOUT], 'datetime', ['notnull' => false, 'default' => null]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_RETRY_COUNT], 'integer');
     $table->addColumn($this->columns[JobReflector::PROPERTY_RETRY], 'boolean', ['notnull' => true, 'default' => false]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_PARAMETERS], 'text', ['notnull' => false, 'default' => null]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_VERSION], 'integer');
     $table->addColumn($this->columns['__CLASS__'], 'string');
     $table->setPrimaryKey(array($this->columns[JobReflector::PROPERTY_ID]));
     $sql = $from->getMigrateToSql($to, $this->connection->getDatabasePlatform());
     $this->connection->beginTransaction();
     foreach ($sql as $query) {
         $this->connection->exec($query);
     }
     $this->connection->commit();
     return;
 }
开发者ID:JackPrice,项目名称:phpq,代码行数:34,代码来源:DoctrineDBALDriver.php

示例12: convertToCharacterSetAndCollation

 /**
  * Convert the tables in the current database to use given character set and collation.
  *
  * @param string $characterSet Character set to convert to
  * @param string $collation Collation to set, must be compatible with the character set
  * @param string $outputPathAndFilename
  * @param boolean $verbose
  * @throws ConnectionException
  * @throws DBALException
  */
 protected function convertToCharacterSetAndCollation($characterSet = 'utf8', $collation = 'utf8_unicode_ci', $outputPathAndFilename = null, $verbose = false)
 {
     $statements = ['SET foreign_key_checks = 0'];
     $statements[] = 'ALTER DATABASE ' . $this->connection->quoteIdentifier($this->persistenceSettings['backendOptions']['dbname']) . ' CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
     $tableNames = $this->connection->getSchemaManager()->listTableNames();
     foreach ($tableNames as $tableName) {
         $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' DEFAULT CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
         $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' CONVERT TO CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
     }
     $statements[] = 'SET foreign_key_checks = 1';
     if ($outputPathAndFilename === null) {
         try {
             $this->connection->beginTransaction();
             foreach ($statements as $statement) {
                 if ($verbose) {
                     $this->outputLine($statement);
                 }
                 $this->connection->exec($statement);
             }
             $this->connection->commit();
         } catch (\Exception $exception) {
             $this->connection->rollBack();
             $this->outputLine($exception->getMessage());
             $this->outputLine('[ERROR] The transaction was rolled back.');
         }
     } else {
         file_put_contents($outputPathAndFilename, implode(';' . PHP_EOL, $statements) . ';');
     }
 }
开发者ID:neos,项目名称:flow-development-collection,代码行数:39,代码来源:DatabaseCommandController.php

示例13: fixVersion

 /**
  * @param string $version
  * @param \DateTime $apply_at
  * @throws \Exception
  */
 public function fixVersion($version, \DateTime $apply_at = null)
 {
     if ($apply_at === null) {
         $apply_at = new \DateTime();
     }
     $this->createTable();
     $this->doctrine->beginTransaction();
     try {
         $this->doctrine->delete(self::TABLE_NAME, array('version' => $version));
         $this->doctrine->insert(self::TABLE_NAME, array('version' => $version, 'apply_at' => $apply_at->format('Y-m-d\\TH:i:s')));
         $this->doctrine->commit();
     } catch (\Exception $ex) {
         $this->doctrine->rollBack();
         throw $ex;
     }
 }
开发者ID:sickhye,项目名称:php-db-migrate,代码行数:21,代码来源:DbTable.php

示例14: commit

 /**
  * @param CommitId $commitId
  * @param Contract $streamContract
  * @param Identifier $streamId
  * @param $expectedStreamRevision
  * @param EventEnvelope[] $eventEnvelopes
  * @throws \Doctrine\DBAL\ConnectionException
  * @throws \Exception
  * @return void
  */
 public function commit(CommitId $commitId, Contract $streamContract, Identifier $streamId, $expectedStreamRevision, array $eventEnvelopes)
 {
     $this->connection->beginTransaction();
     $now = (new DateTimeImmutable('now', new DateTimeZone('UTC')))->format("Y-m-d H:i:s");
     try {
         $this->controlOptimisticConcurrency($streamContract, $streamId, $expectedStreamRevision);
         $nextStreamRevision = $expectedStreamRevision;
         foreach ($eventEnvelopes as $eventEnvelope) {
             $this->connection->executeQuery(Insert::into(self::TABLE_NAME), ['streamContract' => (string) $streamContract, 'streamId' => (string) $streamId, 'streamRevision' => ++$nextStreamRevision, 'eventContract' => (string) $eventEnvelope->getEventContract(), 'eventPayload' => (string) $eventEnvelope->getEventPayload(), 'eventId' => (string) $eventEnvelope->getEventId(), 'commitId' => $commitId, 'utcCommittedTime' => $now]);
         }
         $this->connection->commit();
     } catch (Exception $exception) {
         $this->connection->rollback();
         throw $exception;
     }
 }
开发者ID:dpsarrou,项目名称:EventCentric.Core,代码行数:26,代码来源:MySQLPersistence.php

示例15: commit

 /**
  * Runs the changes to the schema
  */
 public function commit()
 {
     $this->connection->beginTransaction();
     foreach ($this->getChanges() as $sql) {
         $this->connection->query($sql);
     }
     $this->connection->commit();
 }
开发者ID:KasaiDot,项目名称:FoolFrame,代码行数:11,代码来源:SchemaManager.php


注:本文中的Doctrine\DBAL\Connection::beginTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。