简体   繁体   English

哎呀抓住PDO错误?

[英]Whoops to catch PDO errors?

I use whoops on my site, and now I try to get it work with PDO errors, it work fine when there missing a information to connect to the database, but when you (as a example) type a not existing table, it don't show a error. 我在我的网站上使用了whoops ,现在我尝试使用PDO错误,当缺少连接数据库的信息时,它可以正常工作,但当你(作为一个例子)键入一个不存在的表时,它会' t显示错误。

I have try to add PrettyPageHandler::addDataTable() to my error handel 我试着将PrettyPageHandler::addDataTable()添加到我的错误handel

db.php db.php中

class db {

    // just some not important code here...

    // Try to get the result from database.
    try {
        $pdo = DB::getInstance()->db->prepare($sql);
        $pdo->execute($execute);
        $result = $pdo->fetchAll(PDO::FETCH_ASSOC);
        // Return Result
        return $result;
    }
    catch(PDOException $e)
    {
        PrettyPageHandler::addDataTable(null, $e);
    }
}

index.php 的index.php

<?php
if(file_exists("plugins/whoops/autoload.php"))
{
    require_once 'plugins/whoops/autoload.php';
    $whoops = new \Whoops\Run;
    $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
    $whoops->register();
}

require_once db.php';

$db = new db();

but then I get a Class 'PrettyPageHandler' not found 但后来我找不到类'PrettyPageHandler'了

You need to use full class name or use statement. 您需要使用完整的类名use语句。 Change PrettyPageHandler::addDataTable(null, $e); 更改PrettyPageHandler::addDataTable(null, $e); to \\Whoops\\Handler\\PrettyPageHandler::addDataTable(null, $e); to \\Whoops\\Handler\\PrettyPageHandler::addDataTable(null, $e); .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM