dty47696
dty47696
2009-09-09 11:40

PDO:使用mysql INSERT ON DUPLICATE KEY UPDATE检查更新或插入的记录

已采纳

Using PDO / PHP and MySQL, how can I check if a record was inserted or updated when I use an INSERT ON DUPLICATE KEY UPDATE statement?

I have seen a solution using mysql_affected_rows() for PHP, but I am looking for a way I can use with PDO.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dougudu3564 dougudu3564 12年前

    If you use PDO::exec() the return value will be 1 if the row has been inserted and 2 if the row has been updated.

    If you're using a prepared statement and PDOStatement::execute() the same is true for PDOStatement::rowCount()

    点赞 评论 复制链接分享