zoukankan      html  css  js  c++  java
  • symfony 事务提交

    1. 添加数据

     新建一个对象,给对象赋值

    $em = $this->getDoctrine()->getManager(); //添加事物
    $em->getConnection()->beginTransaction(); 
    try { 
      $model= new class();
      $model->setName($name);
      $em->persist($model );
      $em->flush(); 
      $em->getConnection()->commit(); 
    } catch (Exception $ex) {
      $em->getConnection()->rollback();
      throw $ex;
    }
    

      

     2. 修改数据

    Bundle:table
    Bundle名字,和table名
    $Obj = $this->getDoctrine()->getRepository('Bundle:table')->findOneBy(  array('id'=>$id));
    $em = $this->getDoctrine()->getManager(); //添加事物 $em->getConnection()->beginTransaction(); try { $Obj->setName( $name); $em->persist($Obj); $em->flush(); $em->getConnection()->commit(); } catch (Exception $ex) { $em->getConnection()->rollback(); throw $ex; }

      

    3. 删除

    $Obj = $this->getDoctrine()->getRepository('Bundle:table')->findOneBy(  array('id'=>$id));
    $em = $this->getDoctrine()->getManager(); //添加事物
            $em->getConnection()->beginTransaction();        
            try {
                $em->remove($Obj);
                $em->flush();            
                $em->getConnection()->commit(); 
            } catch (Exception $ex) {
                $em->getConnection()->rollback();
                throw $ex;
            }
    

      

  • 相关阅读:
    机器学习
    arm 基本
    阿里RDS备份恢复
    hive 调用java的函数和科学记数法转换
    hive 调用java的函数和科学记数法转换
    hive处理hbase数据
    hive处理hbase数据
    Sqoop导入mysql数据到Hbase
    Sqoop导入mysql数据到Hbase
    Hbase基础操作
  • 原文地址:https://www.cnblogs.com/zgaspnet/p/7606365.html
Copyright © 2011-2022 走看看