dongping5230 2015-12-22 22:21
浏览 67
已采纳

PHP / MySQL查询没有执行

I have two queries I am trying to execute in PHP. For reasons unknown to me only 1 query will execute and the other will not. If I try running the following, the first update works but the 2nd query does not. If I comment the first query and run this, the 2nd update works just fine. Any ideas why this is happening?

$sql = "update " . $_POST["table"] . "_dtl 
        set cd_eff_end_ts = DATE_SUB( '" . $_POST["CD_EFF_STRT_TS"] . "', INTERVAL 1 SECOND) 
        where " . $_POST["pk"] . " = '" . $_POST[$_POST["pk"]] . "' 
            and cd_eff_end_ts = '3500-12-31 23:59:59' 
            and idw_cd_lfcyc_stat_typ_cd in ('RAP', 'RAM')";
$conn->query($sql);

$sql = "update " . $_POST["table"] . "_dtl 
        set rec_eff_strt_ts = current_timestamp, 
            rec_eff_end_ts = '3500-12-31 23:59:59', 
            idw_cd_lfcyc_stat_typ_cd = '" . $status ."', 
            idw_lfcyc_stat_ts = current_timestamp, 
            lfcyc_stat_decreed_by_user_id = " . $user . ", 
            idw_lfcyc_stat_rtnle_txt = '" . $_POST["IDW_LFCYC_STAT_RTNLE_TXT"] . "' 
        where rqst_nbr = " . $_POST["rqst_nbr"];
$conn->query($sql);

Thank you.

  • 写回答

1条回答 默认 最新

  • douzhi9635 2015-12-23 14:40
    关注

    Thanks to the comments from above I realized that there were duplicate keys. There should not be duplicate keys because it is a composite key of both a code and load timestamp. Someone set the load timestamp to current timestamp on update which causes duplicate keys. Removing the on update fixed it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错