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 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line