Reputation:
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:
$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?Upvotes: 1
Views: 48
Reputation: 4372
There is should be no die
you can try code below:
try {
$stmt = $this->pdo->prepare("Select ...");
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_OBJ);
} catch (PDOException $e) {
Log::error("DB-Error (Reservation): ", ['error' => $e->getMessage(), 'errorcode' => (int)$e->getCode()]);
return new stdClass();
} catch (\Exception $e) {
Log::error("Error (Reservation): ", ['error' => $e->getMessage()]);
return new stdClass();
}
Upvotes: 1