Whoops to catch PDO errors?

512 views Asked by At

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.

I have try to add PrettyPageHandler::addDataTable() to my error handel

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

<?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

1

There are 1 answers

5
Jirka Hrazdil On

You need to use full class name or use statement. Change PrettyPageHandler::addDataTable(null, $e); to \Whoops\Handler\PrettyPageHandler::addDataTable(null, $e);.