此PDO准备好的语句返回false,但不会引发错误 [英] This PDO prepared statement returns false but does not throw an error
本文介绍了此PDO准备好的语句返回false,但不会引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码不会引发错误,但是查询失败,即execute
方法返回false.怎么可能呢?
This code does not throw an error but the query fails, that is, the execute
method returns false. How could that be?
require_once("Abstracts/DBManager.php");
require_once("UI/UI.Package.php");
class BlogDBM extends DBManager
{
private $table = "blog_records";
function saveRecord($title,$url,$desc,$feedId,$pubDate)
{
$PDO = $this->db->connect();
try
{
$query = $PDO->prepare("
INSERT INTO ".$this->table."
(title,url,desc,feed_id,pubdate) VALUES
(:title,:url,:desc,:feed_id,:pubdate)");
$query->bindParam(":title", $title);
$query->bindParam(":url", $url);
$query->bindParam(":desc", $desc);
$query->bindParam(":feed_id", $feedId, PDO::PARAM_INT);
$query->bindParam(":pubdate", $pubDate, PDO::PARAM_INT);
$query->execute();
//return $PDO->lastInsertId();
} catch(PDOException $e)
{
echo "Error " . $e->getMessage();
}
$PDO = NULL;
}
}
推荐答案
I'm pretty sure that MySQL chokes on the desc
field name - it is a reserved word. You'd have to put it into "`" quotes or, better, change the field name.
对于错误报告,请使用 errorInfo 方法.您可以使PDO在异常中实际输出失败查询的结果,但是我认为默认行为是仅在根本无法进行查询的情况下引发异常,但在查询不失败的情况下是错误的.
As for error reporting, use the errorInfo method. You can make PDO actually output the result of a failed query in the exception, but the default behaviour - I think - is to throw an exception only if the query can't be made at all, but it doesn't fail if the query is faulty.
这篇关于此PDO准备好的语句返回false,但不会引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文