As the title states, my MySQLi prepared update is not actually updating the database. I have checked the MySQL logs - no errors. Here is the code in question:
正如标题所述,我的MySQLi准备更新实际上并没有更新数据库。我检查了MySQL日志 - 没有错误。这是有问题的代码:
public function update_tweet($tweet)
{
$prepared_update = $this->connection->prepare("UPDATE Tweets
SET `text` = ?, `algo_score` = ?, `has_algo_score` = ?, `baseline_score` = ?, `has_baseline_score` = ?, `is_sanitized` = ?
WHERE `twitter_id` = ?");
mysqli_stmt_bind_param($prepared_update, "sssssss", $tweet['text'], $tweet['algo_score'], $tweet['has_algo_score'], $tweet['baseline_score'], $tweet['has_baseline_score'], $tweet['is_sanitized'], $tweet['tweet_id']);
mysqli_execute($prepared_update) or die(mysqli_error($this->connection));
$prepared_update->close();
}
And an example of the tweet array being passed in:
传递的推文数组的示例如下:
Array ( [id] => 2
[twitter_id] => 595463376026734592
[text] => History has a way of repeating itself
[algo_score] => 0
[has_algo_score] => 1
[baseline_score] => 0
[has_baseline_score] => 1
[is_sanitized] => 1
)
And the table schema:
和表架构:
No PHP errors or MySQL errors. What am I doing wrong?
没有PHP错误或MySQL错误。我究竟做错了什么?
1 个解决方案
#1
Your condition:
WHERE `twitter_id` = ?
The variable that you're binding is:
您绑定的变量是:
$tweet['tweet_id']
While the array you're getting is:
你得到的阵列是:
Array ( [id] => 2
[twitter_id] => 595463376026734592
So you're using the wrong index and since the index tweet_id
is undefined (it's just a notice, you're receiving no errors or warnings) your WHERE
condition would never return true, therefore - no action is being taken.
所以你使用了错误的索引,因为索引tweet_id是未定义的(它只是一个通知,你没有收到任何错误或警告)你的WHERE条件永远不会返回true,因此 - 没有采取任何行动。
#1
Your condition:
WHERE `twitter_id` = ?
The variable that you're binding is:
您绑定的变量是:
$tweet['tweet_id']
While the array you're getting is:
你得到的阵列是:
Array ( [id] => 2
[twitter_id] => 595463376026734592
So you're using the wrong index and since the index tweet_id
is undefined (it's just a notice, you're receiving no errors or warnings) your WHERE
condition would never return true, therefore - no action is being taken.
所以你使用了错误的索引,因为索引tweet_id是未定义的(它只是一个通知,你没有收到任何错误或警告)你的WHERE条件永远不会返回true,因此 - 没有采取任何行动。