• <small id='gErBM'></small><noframes id='gErBM'>

    • <bdo id='gErBM'></bdo><ul id='gErBM'></ul>

      <i id='gErBM'><tr id='gErBM'><dt id='gErBM'><q id='gErBM'><span id='gErBM'><b id='gErBM'><form id='gErBM'><ins id='gErBM'></ins><ul id='gErBM'></ul><sub id='gErBM'></sub></form><legend id='gErBM'></legend><bdo id='gErBM'><pre id='gErBM'><center id='gErBM'></center></pre></bdo></b><th id='gErBM'></th></span></q></dt></tr></i><div id='gErBM'><tfoot id='gErBM'></tfoot><dl id='gErBM'><fieldset id='gErBM'></fieldset></dl></div>
      <tfoot id='gErBM'></tfoot>

      1. <legend id='gErBM'><style id='gErBM'><dir id='gErBM'><q id='gErBM'></q></dir></style></legend>
      2. 在 Symfony2 中捕获数据库异常

        Catching database exceptions in Symfony2(在 Symfony2 中捕获数据库异常)

          <bdo id='bnY0D'></bdo><ul id='bnY0D'></ul>
        • <tfoot id='bnY0D'></tfoot>
          1. <i id='bnY0D'><tr id='bnY0D'><dt id='bnY0D'><q id='bnY0D'><span id='bnY0D'><b id='bnY0D'><form id='bnY0D'><ins id='bnY0D'></ins><ul id='bnY0D'></ul><sub id='bnY0D'></sub></form><legend id='bnY0D'></legend><bdo id='bnY0D'><pre id='bnY0D'><center id='bnY0D'></center></pre></bdo></b><th id='bnY0D'></th></span></q></dt></tr></i><div id='bnY0D'><tfoot id='bnY0D'></tfoot><dl id='bnY0D'><fieldset id='bnY0D'></fieldset></dl></div>

                    <tbody id='bnY0D'></tbody>

                • <legend id='bnY0D'><style id='bnY0D'><dir id='bnY0D'><q id='bnY0D'></q></dir></style></legend>

                  <small id='bnY0D'></small><noframes id='bnY0D'>

                • 本文介绍了在 Symfony2 中捕获数据库异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我遇到了一个无法缩小范围的随机问题.有时,我会在 Symfony2 应用程序中收到以下错误:

                  I've got a random problem that I can't narrow down. Occasionally, I will get the following error in a Symfony2 application:

                  未捕获的异常:驱动程序中发生异常:SQLSTATE[08004] [1040] 连接太多 {"type":1,"file":"/var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php","line":115,"level":30709

                  Uncaught Exception: An exception occured in driver: SQLSTATE[08004] [1040] Too many connections {"type":1,"file":"/var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php","line":115,"level":30709

                  我想设置一个应用程序范围的侦听器来捕获 PDOException 并记录一些信息.我怎样才能挂钩到 Symfony 只捕获 PDOException?

                  I would like to setup an application-wide listener to catch the PDOException and log some information. How can I hook into Symfony to only catch PDOException?

                  推荐答案

                  您需要创建自定义异常侦听器.它将侦听所有异常,但您将在其中指定类型检查.

                  You need to create custom exception listener. It will listen to all exceptions, but you will specify type check inside it.

                  在您的 services.yml 中,您需要指定侦听器:

                  In your services.yml you need to specify listener:

                  kernel.listener.your_pdo_listener:
                          class: AcmeAppBundleEventListenerYourExceptionListener
                          tags:
                             - { name: kernel.event_listener, event: kernel.exception, method: onPdoException }
                  

                  现在你需要创建这个类:

                  Now you need to create this class:

                  你的异常监听器:

                  use SymfonyComponentHttpKernelEventGetResponseForExceptionEvent;
                  class YourExceptionListener
                  {
                       public function onPdoException(GetResponseForExceptionEvent $event)
                       {
                            $exception = $event->getException();
                  
                            if ($exception instanceof PDOException) {
                                //now you can do whatever you want with this exception
                            }
                       }
                  }
                  

                  检查文档 如何创建事件监听器

                  这篇关于在 Symfony2 中捕获数据库异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                        <tbody id='BQuYS'></tbody>
                    1. <tfoot id='BQuYS'></tfoot>

                      <i id='BQuYS'><tr id='BQuYS'><dt id='BQuYS'><q id='BQuYS'><span id='BQuYS'><b id='BQuYS'><form id='BQuYS'><ins id='BQuYS'></ins><ul id='BQuYS'></ul><sub id='BQuYS'></sub></form><legend id='BQuYS'></legend><bdo id='BQuYS'><pre id='BQuYS'><center id='BQuYS'></center></pre></bdo></b><th id='BQuYS'></th></span></q></dt></tr></i><div id='BQuYS'><tfoot id='BQuYS'></tfoot><dl id='BQuYS'><fieldset id='BQuYS'></fieldset></dl></div>

                        <small id='BQuYS'></small><noframes id='BQuYS'>

                            <bdo id='BQuYS'></bdo><ul id='BQuYS'></ul>
                          • <legend id='BQuYS'><style id='BQuYS'><dir id='BQuYS'><q id='BQuYS'></q></dir></style></legend>