PHP - detect mysql update/insertion failure due to violated unique constraint

前端 未结 7 1282
无人及你
无人及你 2020-11-30 11:10

This is kind of similar to this question:

PHP MySQL INSERT fails due to unique constraint

but I have a different twist. Let\'s say I have a table with only

7条回答
  •  無奈伤痛
    2020-11-30 11:47

    Why not just do a select first to see if the entry already exists. Or suppress an error altogether by using INSERT ON DUPLCATE KEY UPDATE, or even use the mysql IGNORE keyword. Why purposely cause an error?

提交回复
热议问题