I have this try and catch:
try {
$stmt = $this->pdo->prepare("Select ...");
$stmt->execute() or die(Log::error("DB-Error (Reservation): ", ['error' => $stmt->errorInfo()]));
return $stmt->fetchAll(PDO::FETCH_OBJ);
} catch (PDOException $e) {
Log::error("DB-Error (Reservation): ", ['error' => $e->getMessage(), 'errorcode' => (int)$e->getCode()]);
return false;
} catch (\Exception $e) {
Log::error("Error (Reservation): ", ['error' => $e->getMessage()]);
return false;
}
I have 1 questions:
- Is this one needed:
$stmt->execute() or die(Log::error("DB-Error (Reservation): ", ['error' => $stmt->errorInfo()]));or can I simply use$stmt->execute() or die();because I catch the error later?
dieat all. If you let the script die at this point, then there will be no catching of anything later - dead is dead.