为什么这个PDO异常没有被抓住?

1 php pdo exception-handling

我有一个INSERT包装在一个try/catch中,但缺少的表没有被捕获,PHP在'$ dbh-> prepare'错误输出.我在'$ dbh-> prepare'为2之前设置了'PDO :: ATTR_ERRMODE'并且回显到浏览器的值.

如果表存在,则INSERT按预期工作.我只是发现在我故意放弃表并运行代码时进行测试时出现问题.

我忽略了什么?

提前致谢

PHP致命错误:带有消息'SQLSTATE [HY000]的未捕获异常'PDOException':常规错误:1在C中没有这样的表:submit_info':\ etc\httpd\htdocs\sqlite_data\gather.php:309

if($our->db['save']) {
    try {
        echo $dbh->getAttribute(constant('PDO::ATTR_ERRMODE'));
        $sth = $dbh->prepare(
            "INSERT INTO submit_info( post_time, post_completed, post_size , script_name, user_agent  )" .
            " VALUES ( datetime(:request_time, 'unixepoch'), datetime(:current_time, 'unixepoch'), :content_length, :script_filename, :user_agent );"
            );
        $sth->bindValue(':request_time', (@$_SERVER['REQUEST_TIME'] + 0), PDO::PARAM_INT);
        $sth->bindValue(':current_time', time(), PDO::PARAM_INT);
        $sth->bindValue(':content_length', (@$_SERVER['CONTENT_LENGTH'] + 0), PDO::PARAM_INT);
        $sth->bindValue(':script_filename', @$_SERVER['SCRIPT_FILENAME'], PDO::PARAM_STR);
        $sth->bindValue(':user_agent', (@$_SERVER['HTTP_USER_AGENT'] . ''), PDO::PARAM_STR);
        $sth->execute();
        $our->db['submit_id'] = $dbh->lastInsertId();
    } catch (PDOExeption $e) {
        echo "There was an error!"; # try writing something to the browser temporarily
        errors("Error writing page load information to database: " . $e->getMessage());
        $our->db['save'] = FALSE;
    }
}
Run Code Online (Sandbox Code Playgroud)

Tim*_*per 6

你拼错了PDOException; 你有PDOExeption(注意失踪c).