user285594
user285594

Reputation:

ZendFramework - How to get the database insert error and stop auto redirection to error page?

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

Answers (1)

RageZ
RageZ

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

Related Questions