Sometimes I get a fatal error in this line
$result = $db->execute($query);
$primary = $result->getRows();
Fatal error: Call to a member function getRows() on a non-object
I'm searching for a solution to catch this error and redirect to index page.
Rewriting something is complicated, because the system is old.