MySQL INSERT …ON DUPLICATE UPDATE - Adds one to the autoincrement

后端 未结 4 570
星月不相逢
星月不相逢 2020-12-09 11:32

I keep track of all the http_user_agents that visit me, with a simple hit counter. The below insert the http_user_agent in the DB, this field is Case Insensitive and is Uniq

4条回答
  •  萌比男神i
    2020-12-09 11:54

    Unfortunately the solution is at the application level if you don't want to affect auto-increment id's. Do a SELECT first and count the result rows. If 0 results, INSERT the data. If more than 0, UPDATE that row.

提交回复
热议问题