douyong8801 2011-05-13 14:44
浏览 84
已采纳

如何在PHP中找到查询“INSERT ... ON DUPLICATE KEY UPDATE ...”的哪一部分成功了?

I have MySQL table that doesn't have AUTO_INCREMENT field. In PHP I run this simple query:

mysql_query("INSERT INTO table ... ON DUPLICATE KEY UPDATE ....");

I need to be able to detect if a new row was inserted into table or if an old row was updated ? Is it possible somehow ?

  • 写回答

1条回答 默认 最新

  • drt41563 2011-05-13 15:08
    关注

    mysql_affected_rows() returns 1 on an insert (because it inserted one row) and 2 on an update (because first it tried to insert, and then it updated, or something like that).

    That is when you're just trying to add one row. You can have the ON DUPLICATE KEY UPDATE clause on multi-row inserts too, and then you'll get the sum of 1's and 2's for all the rows.

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

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件