Reputation:
Trying to insert row, and it fails to insert because of duplicate key found. And throws to error page. But how do i avoid going to error page but simply get the error result? so that i can echo it.
$db->insert("university", $data);
$lastID = $db->lastInsertId();
# when it fails to insert
# how can i run this echo
echo $theCauseOfErrorOnlyDoNotRedirectToError; //??
Upvotes: 2
Views: 3319
Reputation: 27313
you should use a try catch block
try {
$db->insert("university", $data);
$lastID = $db->lastInsertId();
} catch(Exception $e) {
// when it fails to insert
// how can i run this echo
echo $theCauseOfErrorOnlyDoNotRedirectToError; //??
}
You can review the documentation about exceptions and exception handling.
Upvotes: 5