當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CDbConnection::beginTransaction方法代碼示例

本文整理匯總了PHP中CDbConnection::beginTransaction方法的典型用法代碼示例。如果您正苦於以下問題:PHP CDbConnection::beginTransaction方法的具體用法?PHP CDbConnection::beginTransaction怎麽用?PHP CDbConnection::beginTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CDbConnection的用法示例。


在下文中一共展示了CDbConnection::beginTransaction方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testTransactions

 public function testTransactions()
 {
     $transaction = $this->db->beginTransaction();
     $schema = $this->db->schema;
     $builder = $schema->commandBuilder;
     $table = $schema->getTable('posts');
     // Working transaction
     try {
         $builder->createInsertCommand($table, array('title' => 'working transaction test post 1', 'create_time' => '2009-01-01', 'author_id' => 1, 'content' => 'test content'))->execute();
         $builder->createInsertCommand($table, array('title' => 'working transaction test post 2', 'create_time' => '2009-01-01', 'author_id' => 1, 'content' => 'test content'))->execute();
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollback();
     }
     $n = $builder->createCountCommand($table, new CDbCriteria(array('condition' => "title LIKE 'working transaction%'")))->queryScalar();
     $this->assertEquals(2, $n);
     // Failing Transaction
     $transaction = $this->db->beginTransaction();
     try {
         $builder->createInsertCommand($table, array('title' => 'failed transaction test post 1', 'create_time' => '2009-01-01', 'author_id' => 1, 'content' => 'test content'))->execute();
         $builder->createInsertCommand($table, array('id' => 1, 'title' => 'failed transaction test post 2', 'create_time' => '2009-01-01', 'author_id' => 1, 'content' => 'test content'))->execute();
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollback();
     }
     $n = $builder->createCountCommand($table, new CDbCriteria(array('condition' => "title LIKE 'failed transaction%'")))->queryScalar();
     $this->assertEquals(0, $n);
 }
開發者ID:salem-dev-acc,項目名稱:yiiapp,代碼行數:28,代碼來源:CMssqlTest.php

示例2: beginTransaction

 public function beginTransaction()
 {
     if (Yii::app()->params['enable_transactions']) {
         return parent::beginTransaction();
     } else {
         $stub = new OETransactionStub();
         return $stub;
     }
 }
開發者ID:openeyes,項目名稱:openeyes,代碼行數:9,代碼來源:OEDbConnection.php

示例3: runDbScript

 private function runDbScript()
 {
     try {
         $connection = new CDbConnection("{$this->dbDriver}:host={$this->dbHost};dbname={$this->dbName}", $this->dbUser, $this->dbPassword);
         $connection->active = true;
         $sqlFile = Yii::getPathOfAlias('webroot.protected.data') . '/schema.mysql.sql';
         $sql = file_get_contents($sqlFile);
         $connection->beginTransaction();
         $connection->createCommand("SET CHARACTER SET utf8")->execute();
         $command = $connection->createCommand($sql);
         $command->execute(array(':username' => $this->username, ':salt' => $salt = substr(md5(uniqid(rand(), true)), 0, 9), ':password' => sha1($salt . sha1($salt . sha1($this->password))), ':email' => $this->email));
         $connection->getCurrentTransaction()->commit();
         $connection->active = false;
         return true;
     } catch (Exception $ex) {
         return false;
     }
 }
開發者ID:damnpoet,項目名稱:yiicart,代碼行數:18,代碼來源:ConfigurationForm.php

示例4: beginTransaction

 public function beginTransaction()
 {
     $this->db->beginTransaction();
 }
開發者ID:motin,項目名稱:forked-php-orm-benchmark,代碼行數:4,代碼來源:YiiMTestSuite.php

示例5: _do_sync

 private function _do_sync($localTable, $onlineTable, $isLocal)
 {
     $connection = null;
     ini_set('max_execution_time', 9000);
     if ($isLocal) {
         $ipLocal = $_POST["ip"];
         $connection = new CDbConnection("mysql:host={$ipLocal};dbname=sam;", "sam", "54MSyn#");
     } else {
         $connection = new CDbConnection("mysql:host=sam.cbn26zgvuhet.us-east-1.rds.amazonaws.com;dbname=sam;", "mggroup", "5am2oo14#");
     }
     $connection->active = true;
     $transaction = $connection->beginTransaction();
     try {
         $ifMatricula = "";
         if ($localTable == "aud_matricula") {
             $ifMatricula = " estado_auditoria_id IS NOT NULL\n                            AND ";
         } else {
             $ifMatricula = "";
         }
         $queryInsert = "";
         if ($isLocal) {
             $queryInsert = "SELECT\n                            *\n                          FROM\n{$localTable}\n                          WHERE fecha_actualizacion IS NOT NULL";
         } else {
             $queryInsert = "SELECT\n                            *\n                          FROM\n{$localTable}\n                          WHERE fecha_sincronizacion IS NULL\n                            AND fecha_actualizacion IS NOT NULL\n                            OR fecha_sincronizacion < fecha_actualizacion limit 1000";
         }
         $dataLocal = Yii::app()->db->createCommand($queryInsert)->queryAll();
         $command = $connection->createCommand();
         foreach ($dataLocal as $item => $itemValue) {
             if (!$isLocal) {
                 $itemValue["fecha_sincronizacion"] = date("Y-m-d H:i:s");
             }
             $command->insert($onlineTable, $itemValue);
         }
         $transaction->commit();
         if (!$isLocal) {
             $queryInsert = "UPDATE\n{$localTableSET}\n" . $localTable . " .fecha_sincronizacion = NOW()\n                                            WHERE fecha_sincronizacion IS NULL\n                                            AND fecha_actualizacion IS NOT NULL\n                                            OR fecha_sincronizacion < fecha_actualizacion ";
             Yii::app()->db->createCommand($queryInsert)->execute();
         }
         return true;
     } catch (Exception $exc) {
         $transaction->rollBack();
         echo $exc->getMessage();
         return false;
     }
 }
開發者ID:MGGROUP,項目名稱:SAMDEPURACION,代碼行數:45,代碼來源:SiteController.php


注:本文中的CDbConnection::beginTransaction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。