getting mysql_insert_id() while using ON DUPLICATE KEY UPDATE with PHP

后端 未结 4 1427
南旧
南旧 2020-12-05 02:52

I\'ve found a few answers for this using mySQL alone, but I was hoping someone could show me a way to get the ID of the last inserted or updated row of a mysql DB when using

4条回答
  •  青春惊慌失措
    2020-12-05 03:34

    You could check if the Query was an insert or an update ( mysql_affected_rows(); returns 1 on insert and 2 on update).

    If it was an insert use mysql_insert_id, if it was an update you'd need another Query.

    
    

    I know it's not excatly what your looking for but it's the best i could come up with

提交回复
热议问题