PDOStatement: Duplicate entry 'exa...@example.com' for key 'email'
What's the best way to catch this error and do something about it? Suppose this was a form post to create a new record, it would be nice to show an error message about entering a different email address.
If the code was something like this:
$user = new \DB\SQL\Mapper($db, 'users');
$user->email = 'exa...@example.com';
$user->password = 'secret';
$user->save(); // This line needs some sort of condition to catch errors
What are the best practices for catching insert failures and handling them appropriately?
Thanks for the help!