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.

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料