问题
I'm getting a "Duplicate entry 'blah' for key 'username'" error message, but I would LOVE for it to read "This username already exists".
Is that possible? If so, where and how would I go about changing that?
I'm using PHP, MySQL and phpmyadmin.
Sorry for my noobishness. Thanks in advance.
回答1:
$result = mysql_query('... query that produces duplicate key error ...');
if ($result === FALSE) {
if (mysql_errno() == 1022) {
die("Username already exists");
} else {
die(mysql_error());
}
}
The error codes are documented here: http://dev.mysql.com/doc/refman//5.5/en/error-messages-server.html and you can write your own custom error handler to output 'nicer' error messages if you so desire.
来源:https://stackoverflow.com/questions/10202818/can-you-customize-a-mysql-error-duplicate-error-message