Skip to content

A free, self-hostable news aggregator…

Avoid exception in searchById (#4822)

Alexandre Alapetite2c0f3fad2d1e
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index e098c65e4..20a92d52a 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -228,16 +228,16 @@ SQL;
public function searchById($id) {
$sql = 'SELECT * FROM `_category` WHERE id=:id';
$stm = $this->pdo->prepare($sql);
- $stm->bindParam(':id', $id, PDO::PARAM_INT);
- $stm->execute();
- $res = $stm->fetchAll(PDO::FETCH_ASSOC);
- $cat = self::daoToCategory($res);
-
- if (isset($cat[0])) {
- return $cat[0];
- } else {
- return null;
+ if ($stm &&
+ $stm->bindParam(':id', $id, PDO::PARAM_INT) &&
+ $stm->execute()) {
+ $res = $stm->fetchAll(PDO::FETCH_ASSOC);
+ $cat = self::daoToCategory($res);
+ if (isset($cat[0])) {
+ return $cat[0];
+ }
}
+ return null;
}
/** @return FreshRSS_Category|null|false */