• <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 中捕获数据库异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)
                        <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>