當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。