dtwupu6414 2012-02-11 03: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-11 03:57
    关注

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

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

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了