用Doctrine 2检查重复的键 [英] Checking for duplicate keys with Doctrine 2

查看:56
本文介绍了用Doctrine 2检查重复的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

你可以捕捉到 UniqueConstraintViolationException 如此:

 使用Doctrine\DBAL\Exception\UniqueConstraintViolationException; 

// ...

try {
// ...
$ em-> flush();
}
catch(UniqueConstraintViolationException $ e){
// ....
}


Is there an easy way to check for duplicate keys with Doctrine 2 before doing a flush?

解决方案

You can catch the UniqueConstraintViolationException as such:

use Doctrine\DBAL\Exception\UniqueConstraintViolationException;

// ...

try {
   // ...
   $em->flush();
}
catch (UniqueConstraintViolationException $e) {
    // ....
}

这篇关于用Doctrine 2检查重复的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆