我知道这是一个愚蠢的问题,我知道我的代码有什么问题,但无法弄清楚错误是什么。
function saveEvent($event_id,$old_category_id,$old_site_id,$old_user_id,$old_name,$old_description,$old_standby_start,$old_standby_end,$old_standby_reason,$old_standby_conclusion,$category_id,$site_id,$user_id,$name,$description,$standby_start_date,$standby_start_time,$standby_end_date,$standby_end_time,$standby_reason,$standby_conclusion)
{
$standby_start = $standby_start_date." ".$standby_start_time.":00";
$standby_end = $standby_end_date." ".$standby_end_time.":00";
// create new pdo object
$pdo = dbConnect();
try
{
$pdo->beginTransaction();
$req = $pdo->prepare("INSERT INTO t_events_changes
(ec_event_id,ec_old_category,ec_new_category,
ec_old_site,ec_new_site,ec_old_author,ec_new_author,ec_timestamp,
ec_old_name,ec_new_name,ec_old_description,ec_new_description,
ec_old_standby_start,ec_new_standby_start,ec_old_standby_end,
ec_new_standby_end,ec_old_standby_reason,ec_new_standby_reason,
ec_old_standby_conclusion,ec_new_standby_conclusion)
VALUES (:event_id,:old_category_id,:new_category_id,
:old_site_id,:new_site_id,:old_author_id,:new_author_id,NOW(),
:old_name,:new_name,:old_description,:new_description,
:old_standby_start,:new_standby_start:old_standby_end,
:new_standby_end,:old_standby_reason,:new_standby_reason,
:old_standby_conclusion,:new_standby_conclusion);");
$req->execute(array(
':event_id' => $event_id,
':old_category_id' => $old_category_id,
':new_category_id' => $category_id,
':old_site_id' => $old_site_id,
':new_site_id' => $site_id,
':old_author_id' => $old_user_id,
':new_author_id' => $user_id,
':old_name' => $old_name,
':new_name' => $name,
':old_description' => $old_description,
':new_description' => $description,
':old_standby_start' => $old_standby_start,
':new_standby_start' => $standby_start,
':old_standby_end' => $old_standby_end,
':new_standby_end' => $standby_end,
':old_standby_reason' => $old_standby_reason,
':new_standby_reason' => $standby_reason,
':old_standby_conclusion' => $old_standby_conclusion,
':new_standby_conclusion' => $standby_conclusion
));
$req2 = $pdo->prepare("UPDATE t_events
SET t_categories_category_id = :category_id,
t_sites_site_id = :site_id,
t_users_user_id = :user_id,
e_last_change = NOW(),
e_name = :name,
e_description = :description,
e_standby_start = :standby_start,
e_standby_end = :standby_end,
e_standby_reason = :standby_reason,
e_standby_conclusion = :standby_conclusion
WHERE event_id = :event_id");
$req2->bindParam(':category_id',$category_id,PDO::PARAM_STR);
$req2->bindParam(':site_id',$site_id,PDO::PARAM_STR);
$req2->bindParam(':user_id',$user_id,PDO::PARAM_STR);
$req2->bindParam(':name',$name,PDO::PARAM_STR);
$req2->bindParam(':description',$description,PDO::PARAM_STR);
$req2->bindParam(':standby_start',$standby_start,PDO::PARAM_STR);
$req2->bindParam(':standby_end',$standby_end,PDO::PARAM_STR);
$req2->bindParam(':standby_reason',$standby_reason,PDO::PARAM_STR);
$req2->bindParam(':standby_conclusion',$standby_conclusion,PDO::PARAM_STR);
$req2->bindParam(':event_id',$event_id,PDO::PARAM_STR);
$pdo->commit();
echo 'Update complete';
}
catch(Exception $e)
{
// rollback the transaction
$pdo->rollback();
// display error message and datas
echo 'Tout ne s\'est pas bien passé, voir les erreurs ci-dessous<br />';
echo 'Erreur : '.$e->getMessage().'<br />';
echo 'N° : '.$e->getCode();
// exit the catch to avoid the next errors
exit();
}
}
也许我是瞎子,也许这个错误来自别的东西,但我现在正在读我的代码一小时但仍然不明白问题出在哪里
答案 0 :(得分:0)
在此行中缺少逗号(,)。由于哪个绑定变量不匹配。
$req = $pdo->prepare("INSERT INTO t_events_changes ....
Values (... :new_standby_start:old_standby_end, ... )");
^ here missing comma
将其更改为,
:new_standby_start,:old_standby_end,