Why isn't this PDO Exception getting caught?

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:etchttpdhtdocssqlite_datagather.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;
    }
}

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

链接地址: http://www.djcxy.com/p/69168.html

上一篇: PDO PHP双记录插入

下一篇: 为什么这个PDO异常被捕获?