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


PHP Connection::transaction方法代码示例

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


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

示例1: ensureTransaction

 /**
  * Enures the given closur is executed within a PDO transaction.
  *
  * @param  Closure  $callback
  * @return void
  */
 public function ensureTransaction(Closure $callback)
 {
     if (!$this->connection->getPdo()->inTransaction()) {
         $this->connection->transaction($callback);
     } else {
         $callback($this->connection);
     }
 }
开发者ID:sohailaammarocs,项目名称:lfc,代码行数:14,代码来源:IlluminateWorker.php

示例2: requestPasswordResetForEmail

 /**
  * Request a password reset for a given email.
  *
  * @param  string $email
  *
  * @return bool
  */
 public function requestPasswordResetForEmail($email)
 {
     if ($this->reminders === null) {
         throw new \RuntimeException('Password reset service not set.');
     }
     return $this->db->transaction(function () use($email) {
         $user = $this->users->findByCredentials(['email' => $email]);
         if (!$user) {
             throw new Reminders\ReminderException();
         }
         return $this->reminders->requestReset($user);
     });
 }
开发者ID:anlutro,项目名称:l4-core,代码行数:20,代码来源:UserManager.php

示例3: transaction

 /**
  * Execute a Closure within a transaction.
  *
  * @param  \Closure  $callback
  * @return mixed
  *
  * @throws \Exception
  */
 public function transaction(Closure $callback)
 {
     if ($this->getDriverName() == 'sqlsrv') {
         return parent::transaction($callback);
     }
     $this->pdo->exec('BEGIN TRAN');
     // We'll simply execute the given callback within a try / catch block
     // and if we catch any exception we can rollback the transaction
     // so that none of the changes are persisted to the database.
     try {
         $result = $callback($this);
         $this->pdo->exec('COMMIT TRAN');
     } catch (Exception $e) {
         $this->pdo->exec('ROLLBACK TRAN');
         throw $e;
     }
     return $result;
 }
开发者ID:PrafullaKumarSahu,项目名称:wordpress-socializr,代码行数:26,代码来源:SqlServerConnection.php

示例4: revokePrivileges

 /**
  * @param Connection $db
  * @param array      $creds
  * @param string     $fromServer
  *
  * @return bool
  */
 protected function revokePrivileges($db, $creds, $fromServer)
 {
     return $db->transaction(function () use($db, $creds, $fromServer) {
         //  Create users
         $_users = $this->getDatabaseUsers($creds, $fromServer);
         try {
             foreach ($_users as $_user) {
                 //	Grants for instance database
                 if (!($_result = $db->statement('REVOKE ALL PRIVILEGES ON ' . $creds['database'] . '.* FROM ' . $_user))) {
                     $this->error('[provisioning:database] error revoking privileges from "' . $_user . '"');
                     continue;
                 }
                 $this->debug('[provisioning:database] grants revoked - complete');
                 if (!($_result = $db->statement('DROP USER ' . $_user))) {
                     $this->error('[provisioning:database] error dropping user "' . $_user . '"');
                 }
                 $_result && $this->debug('[provisioning:database] users dropped > ', $_users);
             }
             return true;
         } catch (\Exception $_ex) {
             $this->error('[provisioning:database] revoke grants - failure: ' . $_ex->getMessage());
             return false;
         }
     });
 }
开发者ID:rajeshpillai,项目名称:dfe-dreamfactory-provisioner,代码行数:32,代码来源:DatabaseProvisioner.php


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