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
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.