我有一个包含在 try/catch 中的 INSERT,但是没有捕获丢失的表,并且 PHP 在“$dbh->prepare”处出错。
我已经设置了“PDO::ATTR_ERRMODE”,并且在“$dbh->prepare”之前回显到浏览器的值是 2。
如果该表存在,则 INSERT 按我的预期工作。当我故意删除表并运行代码时,我才在测试时发现存在问题。
我忽略了什么?
提前致谢
PHP 致命错误:未捕获异常“PDOException”,消息“SQLSTATE[HY000]:一般错误:1 在 C:\etc\httpd\htdocs\sqlite_data\gather.php 中没有这样的表:submit_info”: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;
}
}