一起源码网

  • www.171739.xyz
  • 全球最大的互联网技术和资源下载平台
搜索
猜你喜欢
查看: 4851|回复: 1
打印 上一主题 下一主题

symfony 事务提交方法

[复制链接]

0

主题

0

帖子

1万

积分

钻石会员

Rank: 8Rank: 8

积分
17424
QQ
跳转到指定楼层
楼主
发表于 2020-5-9 09:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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('')->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;
        }

分享到:  QQ好友和群QQ好友和群
收藏收藏
回复

使用道具 举报

0

主题

18

帖子

56

积分

注册会员

Rank: 2

积分
56
沙发
发表于 2022-10-5 18:48 | 只看该作者
2021免费音乐下载
回复

使用道具 举报

一起源码让程序更轻更快

www.171739.xyz

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表