当前位置: 首页>>代码示例>>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;未经允许,请勿转载。