Is there a way to distinguish between error messages returned by MySQL when the query is formed incorrectly VS when the user input is wrongly entered?
For example:
//WRONG QUERY
try {
INSERT into table_name ('clm1','clm2') values('val1','val2'); //BAD query
}
catch (PDOException $e) {
echo $e->getMessage(); //display the error message returned
}
VS.
//wrong user input
try {
INSERT INTO table_name ('unique_clm1') value('duplicate_value_from_user');
}
catch (PDOException $e) {
echo $e->getMessage(); //display the error message returned
}
REASON:
If there is an error in query written by the developer; the error needs to be displayed as a raw MySQL error for debugging......while a bad user entry needs to be shown as an error message to the user without disrupting the normal flow of code.....