$dbh->beginTransaction();
$content = "数据表中已经有相同的内容了。";
if (!empty($content)) {
$sql = "SELECT * FROM Contents WHERE Content = ?";
$stmt = $dbh->prepare($sql);
$stmt->execute(array($content));
/*$stmt->bindValue(1, $content);
$stmt->execute();*/
if ($stmt->rowCount()){
echo "数据表中已经有相同的内容了。";
} else {
$sql = "INSERT INTO Contents (Content, TimeCreated) VALUES (:content, NOW())";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(":content", $content);
$successful = $stmt->execute();
$dbh->rollBack();
echo "rollback";
/*if ($successful) {
$num = $stmt->rowCount();
echo "插入了{$num}条记录。";
//echo $stmt->queryString;
} else {
echo "插入记录失败!";
}*/
}
} else {
echo "没有内容";
}