dtwupu6414 2012-02-10 19:55
浏览 31
已采纳

为什么这个PDO异常没有被抓住? [关闭]

I have an INSERT wrapped in a try/catch, but a missing table is not getting caught and PHP is erroring out at '$dbh->prepare'. I've set the 'PDO::ATTR_ERRMODE' and the value echoed to the browser just before the '$dbh->prepare' is 2.

If the table exists, the INSERT works as I expected. I only discovered there was an issue while testing when I purposely dropped the table and ran the code.

What have I overlooked?

Thanks in advance

PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 no such table: submit_info' in C:\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;
    }
}
  • 写回答

1条回答 默认 最新

  • dongyukang7006 2012-02-10 19:57
    关注

    You misspelt PDOException; you have PDOExeption (note the missing c).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部