我已经构建了一个 php 脚本来保存哈希标记搜索的结果,当我保存推文 ID 时,它只是尝试保存一个副本。我在表上设置了一个 UNIQUE 约束,它显然只保存了第一条推文,并抛出了下面的错误。这并不奇怪
ERROR: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2147483647' for key 2
如果我删除约束,它会正确保存所有推文,但推文 ID 是重复的
我尝试在输出中显示来自我用来放入表中的同一变量的推文,它都是唯一且正确的,因此变量是正确的。所以我只能假设一些奇怪的事情本身就在发生
foreach($results as $result) {
$tweet_ID = $result->id_str;
$userID = $result->from_user_id_str;
$tweetText = $result->text;
$tweet_time = strtotime($result->created_at);
$createdAt = date('Y-m-d H:i:s ',$tweet_time);
echo '<div>'. $tweet_ID .
'<div class="tweet" >' . displayTweet($result->text),"\r\n" .
'<div class="user">'. '<strong>Posted </strong>' . date('j/n/y H:i:s ',$tweet_time). '<strong> By </strong>' .
'<a rel="nofollow" href="http://twitter.com/' . $result->from_user. '">' . $result->from_user .
'</div>' .
'</div>';
// Execute query
$stmt = $conn->prepare("INSERT INTO ".$hashtag."(tweetID, userID, tweetText, createdAt) VALUES(:tweetID, :userID, :tweetText, :createdAt)");
$stmt->execute(array(':tweetID' => $tweet_ID, ':userID' => $userID, ':tweetText' => $tweetText, ':createdAt' => $createdAt));
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
我无法弄清楚为什么它会保存一些随机数
它添加的数字是 2147483647。对我来说没有任何意义。任何有关正在发生的事情的帮助将不胜感激