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

前端 未结 7 1307
无人及你
无人及你 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:48

    I believe the error code for duplicate keys is 1586. If you were to attempt to execute a query and then, on failure, check the error code using mysql_errno()/mysqli::errno() and compare it to 1586, that should do it. If it's not 1586, check what it actually is by echoing the error code after your query.

提交回复
热议问题