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
From PHP Documentation on the function mysql_errno
:
Returns the error number from the last MySQL function,
or 0 (zero) if no error occurred.
Also, from MySQL Documentation on Constraint Violation Errors, error code 893 corresponds to:
Constraint violation e.g. duplicate value in unique index
So, we can then write something like this to do the work:
if (!$result) {
$error_code = mysql_errno();
if ($error_code == 893) {
// Duplicate Key
} else {
// Some other error.
}
}