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


PHP Connection::beginTransaction方法代码示例

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


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

示例1: fetchJob

 /**
  * Return next job from the queue.
  * @return Job|boolean the job or false if not found.
  */
 protected function fetchJob()
 {
     //Avoiding multiple job.
     $transaction = $this->db->beginTransaction();
     $row = $this->fetchLatestRow();
     if ($row == false || !$this->flagRunningRow($row)) {
         $transaction->rollBack();
         return false;
     }
     $transaction->commit();
     $job = $this->deserialize($row['data']);
     $job->id = $row['id'];
     $job->header['timestamp'] = $row['timestamp'];
     return $job;
 }
开发者ID:voodoo-mobile,项目名称:yii2-queue,代码行数:19,代码来源:DbQueue.php

示例2: insertOrderBase

 /**
  * 批量插入订单的基本信息
  * @param array $orderBaseArray
  * @throws \yii\db\Exception
  */
 public function insertOrderBase(array $orderBaseArray)
 {
     if (!empty($orderBaseArray)) {
         $tableName = 't_oms_order';
         $tableFields = [];
         $tableValues = [];
         foreach ($orderBaseArray as $orderBase) {
             if (empty($tableFields)) {
                 $tableFields = array_keys($orderBase);
             }
             $tableValues[] = array_values($orderBase);
         }
         $transaction = $this->db->beginTransaction();
         $this->db->createCommand()->batchInsert($tableName, $tableFields, $tableValues)->execute();
         $transaction->commit();
     }
 }
开发者ID:xidiao,项目名称:gxfenxi,代码行数:22,代码来源:InsertOrder.php

示例3: beginTransaction

 /**
  * Starts a transaction.
  * @param string|null $isolationLevel The isolation level to use for this transaction.
  * See [[Transaction::begin()]] for details.
  * @return Transaction the transaction initiated
  */
 public function beginTransaction($isolationLevel = null)
 {
     $transaction = parent::beginTransaction(null);
     if ($isolationLevel !== null) {
         $transaction->setIsolationLevel($isolationLevel);
     }
     return $transaction;
 }
开发者ID:edgardmessias,项目名称:yii2-informix,代码行数:14,代码来源:Connection.php

示例4: applyMigration

 /**
  * Applies migration
  *
  * @param array $migration
  * @return void
  * @throws \yii\db\Exception
  */
 protected function applyMigration($migration)
 {
     ob_start();
     if ($this->direction == 'up') {
         $appliedMigrations = $this->getAppliedMigrations();
         if (!isset($appliedMigrations[$migration['name']])) {
             $migrateObj = $this->createMigration($migration);
             if (method_exists($migrateObj, 'safeUp')) {
                 $transaction = $this->_db->beginTransaction();
                 try {
                     if ($migrateObj->safeUp() !== false) {
                         $this->addMigrationHistory($migration);
                         $transaction->commit();
                     } else {
                         $transaction->rollBack();
                     }
                 } catch (Exception $e) {
                     $transaction->rollBack();
                     $this->error = $e;
                 }
             } else {
                 try {
                     if ($migrateObj->up() !== false) {
                         $this->addMigrationHistory($migration);
                     }
                 } catch (Exception $e) {
                     $this->error = $e;
                 }
             }
         }
     } elseif ($this->direction == 'down') {
         $migrateObj = $this->createMigration($migration);
         if (method_exists($migrateObj, 'safeDown')) {
             $transaction = $this->_db->beginTransaction();
             try {
                 if ($migrateObj->safeDown() !== false) {
                     $this->removeMigrationHistory($migration);
                     $transaction->commit();
                 } else {
                     $transaction->rollBack();
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
                 $this->error = $e;
             }
         } else {
             try {
                 if ($migrateObj->down() !== false) {
                     $this->removeMigrationHistory($migration);
                 }
             } catch (Exception $e) {
                 $this->error = $e;
             }
         }
     }
     ob_end_clean();
 }
开发者ID:radiata-cms,项目名称:radiata,代码行数:64,代码来源:Migrator.php

示例5: import

 /**
  * Обновление базы данных
  */
 public function import(array $translateArray)
 {
     $query = new Query();
     $transaction = $this->_db->beginTransaction();
     try {
         // Обходим каждую категорию
         foreach ($translateArray as $category => &$messages) {
             // обходим каждую константу
             foreach ($messages as $constant => &$message) {
                 // Достаем константу с переводов в указанной категории
                 $selectCategory = $query->from($this->_sourceMessageTable)->where(['category' => $category, 'message' => $constant])->createCommand($this->_db)->queryOne();
                 // Если такая константа уже существует, необходимо обновить перевод
                 if ($selectCategory) {
                     $constantId = $selectCategory['id'];
                 } else {
                     // Если такой константы нет, создадим ее
                     $insert = $this->_db->createCommand()->insert($this->_sourceMessageTable, ['category' => $category, 'message' => $constant])->execute();
                     $constantId = $this->_db->lastInsertID;
                 }
                 // обходим каждый перевод сообщения
                 foreach ($message as $lang => &$translate) {
                     // Достаем перевод исходя из константы и языка
                     $selectTranslate = $query->from($this->_messageTable)->where(['id' => $constantId, 'language' => $lang])->createCommand($this->_db)->queryOne();
                     // Если такой перевод есть, небходимо его обновить
                     if ($selectTranslate) {
                         // Обновляем только в том случае, если действительно есть изменения
                         if ($selectTranslate['translation'] !== $translate && $this->_update) {
                             $update = $this->_db->createCommand()->update($this->_messageTable, ['translation' => $translate], ['id' => $constantId, 'language' => $lang])->execute();
                         }
                     } else {
                         // Если перевода нет, вносим его
                         $insert = $this->_db->createCommand()->insert($this->_messageTable, ['id' => $constantId, 'language' => $lang, 'translation' => $translate])->execute();
                     }
                 }
             }
         }
         $transaction->commit();
         return true;
     } catch (\Exception $e) {
         $transaction->rollBack();
         throw new InvalidParamException($e->getMessage());
     }
 }
开发者ID:nepster-web,项目名称:yii2-messages-importer,代码行数:46,代码来源:DbMessageImporter.php

示例6: delete

 /**
  * @param int|string $userId
  * @param string $key
  * @return bool
  * @throws \yii\db\Exception
  */
 public function delete($userId, $key)
 {
     $transaction = $this->db->beginTransaction();
     $result = $this->deleteFromDb($userId, $key) && $this->deleteFromCache($userId, $key);
     if ($result) {
         $transaction->commit();
     } else {
         $transaction->rollBack();
     }
     return $result;
 }
开发者ID:cdcchen,项目名称:yii-plus,代码行数:17,代码来源:UserConfig.php

示例7: beginTransaction

 public function beginTransaction()
 {
     $this->db->beginTransaction();
 }
开发者ID:motin,项目名称:forked-php-orm-benchmark,代码行数:4,代码来源:Yii2MTestSuite.php

示例8: actionUpdate

 /**
  * @throws \yii\base\InvalidConfigException
  * @throws \yii\db\Exception
  */
 public function actionUpdate()
 {
     $assignments = $this->getAllAssignments();
     $useTransaction = $this->authManager instanceof \yii\rbac\DbManager && $this->useTransaction === true;
     $transaction = null;
     if ($useTransaction) {
         $transaction = $this->db->beginTransaction();
     }
     try {
         $this->authManager->removeAll();
         $this->updateRules();
         $this->updateRoles();
         $this->updatePermission();
         $this->updateInheritanceRoles();
         $this->updateInheritancePermissions();
         if (!empty($assignments)) {
             $this->restoreAssignments($assignments);
         }
         if ($transaction !== null) {
             $transaction->commit();
         }
     } catch (\Exception $e) {
         $this->stderr($e->getMessage() . PHP_EOL);
         if ($transaction !== null) {
             $transaction->rollBack();
         }
     }
     if ($this->authManager instanceof \yii\rbac\DbManager) {
         $this->authManager->invalidateCache();
     }
 }
开发者ID:rmrevin,项目名称:yii2-rbac-command,代码行数:35,代码来源:Command.php


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