PHP MySQL INSERT fails due to unique constraint

Posted by sjw on Stack Overflow See other posts from Stack Overflow or by sjw
Published on 2010-05-03T04:57:54Z Indexed on 2010/05/03 5:08 UTC
Read the original article Hit count: 295

Filed under:
|
|

On insert I am catching the unique constraint mysql_errno() 1062.

This works fine but I want to find the existing row to re-instate or modify it.

Is there are method to obtain the row id on insert fail? I tried mysql_insert_id() but realised that would only return the row I'm inserting (or failed to insert) therefore, I get 0.

Is there no option but to issue another mysql_query and simply perform a select on the duplicate value?

I just want to make sure there is no better, quicker, more economical way to do this.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql