绑定变量的数量与标记的数量不匹配 - MySQl

Number of bound variables does not match number of tokens - MySQl

更好的标题可能是 "I can't count" :-(

这段代码有什么问题?应该是很明显的,但是我看不出来。

if (isset($_GET['campaign_id']))
{
    ChromePhp::log('API: request to update existing campaign "' . $campaignTitle . '"');
    $sqlCommand = $pdo->prepare('UPDATE campaigns SET title=:title, description=:description, start_time=:start_time, end_time:end_time) WHERE (customer_id=:customer_id) AND (campaign_id=:campaign_id)');
    $sqlCommand->bindParam(':campaign_id', $_GET['campaign_id']);
}
else
{
    ChromePhp::log('API: request to add a new campaign "' . $campaignTitle . '"');
    $sqlCommand = $pdo->prepare('INSERT INTO campaigns (customer_id, title, description, start_time, end_time) VALUES(:customer_id, :title, :description, :start_time, :end_time)');
}

$sqlCommand->bindParam(':customer_id', $customerId);
$sqlCommand->bindParam(':title', $campaignTitle);
$sqlCommand->bindParam(':description', $campaignDescription);
$sqlCommand->bindParam(':start_time', $startTimeStamp);
$sqlCommand->bindParam(':end_time', $endTimeStamp);
$sqlResult = DatabaseCommand($sqlCommand);

正在浏览

http://localhost/api/addCampaign.php?customer=1&title=t&description=d&startTimeStamp=1443313713&endTimeStamp=1443313713&campaign_id=5

给予Message: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

浏览器的开发者控制台日志显示API: request to update existing campaign "t"

谁能让我摆脱痛苦并让我说 "D'oh!"?

评论有点长。我不知道为什么你会收到 that 消息,但你在 update:

中有这个片段
end_time:end_time

这应该是

end_time = :end_time

也许这会解决您的问题。