From 99a04db1c6db98e40bda0d07538c4a5871c44dfd Mon Sep 17 00:00:00 2001 From: LordSchmackes Date: Fri, 22 May 2026 19:25:06 +0200 Subject: [PATCH] T --- config.php | 9 +++++++-- helpers.php | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/config.php b/config.php index 441d1a5..7a9c641 100644 --- a/config.php +++ b/config.php @@ -37,13 +37,17 @@ load_env(); /** * Get a PDO connection to the database. */ -function get_db_connection(): ?PDO { +function get_db_connection() { static $pdo = null; if ($pdo !== null) { return $pdo; } + if (!class_exists('PDO')) { + return null; + } + $url = getenv('DATABASE_URL'); if (!$url) { return null; @@ -66,9 +70,10 @@ function get_db_connection(): ?PDO { $pdo = new PDO($dsn, $user, $pass, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_TIMEOUT => 3, ]); return $pdo; - } catch (PDOException $e) { + } catch (\Exception $e) { error_log("Database connection failed: " . $e->getMessage()); return null; } diff --git a/helpers.php b/helpers.php index 21f8045..d1b0147 100644 --- a/helpers.php +++ b/helpers.php @@ -38,7 +38,7 @@ function init_db() { } } } - } catch (PDOException $e) { + } catch (\Exception $e) { error_log("DB Init Error: " . $e->getMessage()); } } @@ -70,7 +70,7 @@ function load_recipes_local(): array { } } } - } catch (PDOException $e) { + } catch (\Exception $e) { error_log("Failed to load recipes from DB: " . $e->getMessage()); } }