抓住Zend PDO异常 [英] Catch Zend PDO Exception

查看:193
本文介绍了抓住Zend PDO异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我是否可以尝试了解 $ application-> bootstrap() - > run();

这将捕获 pdo异常



这样做可以捕获每一个我不想要的异常。 p>

  try {
$ application-> bootstrap() - > run();
} catch(Exception $ e){
print_r($ e);
}

我有一个令人讨厌的pdo异常事件被抛出并显示来自应用程序的密码.ini!



值得注意的是,我尝试过PDOException,它没有被捕获。



我的数据库是在bootstrap run()中设置$($)
$ b $ ) - > getDbAdapter();
Zend_Registry :: set('dbAdapter',$ db);
} catch(Exception $ e){
echo 1; exit;
}

请注意,如果我在本地输入错误的密码并运行该应用程序,没有看到1,即使有错误报告,我也看到一个空白页。

解决方案

去哪里你有数据库代码尝试了解该代码。如果您只想要Pdo异常,那么只能捕获PdoException。放置像catch(PdoExcetion_OR_What_Its_Name_Is $ e)(并将错误输出禁用到屏幕上)将您的错误写入日志文件)


I'm wondering if I can put a try catch about $application->bootstrap()->run();
that will catch pdo exceptions

This works, but it catches every exception, which I do not want.

try {
    $application->bootstrap()->run();
} catch (Exception $e) {
    print_r($e);
}

I had a nasty incident of pdo exception being throw and displaying the password from application.ini!

Worthy of note, I have tried PDOException, it doesnt get catched.

My DB is set up in bootstrap run() with

    try {
        $db = $this->getPluginResource('db')->getDbAdapter();
        Zend_Registry::set('dbAdapter', $db);
    } catch (Exception $e) {
        echo 1;exit;
    }

Note that if I put in the wrong password locally and run the app, I do not see 1, I see a blank page even with error reporting on.

解决方案

Go where you have the database code and put try catch around that code. If you want only Pdo Exceptions then catch only PdoException. Put something like catch(PdoExcetion_OR_What_Its_Name_Is $e) (And disable the error output to the screen. Write your errors to a log file)

这篇关于抓住Zend PDO异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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