From d42180d2be05f4b981d8be126e2fe2e572da0946 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 2 Sep 2019 21:34:39 +0200 Subject: [PATCH] Pass possible exception from SQLite3_connect_try() to the calling process. This makes this function return either valid SQLite3 objects (success) or strings (errors). We can pass the errors to the user interface to help user helping themselves. Signed-off-by: DL6ER --- scripts/pi-hole/php/database.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/pi-hole/php/database.php b/scripts/pi-hole/php/database.php index d4893d71..f98f2b8a 100644 --- a/scripts/pi-hole/php/database.php +++ b/scripts/pi-hole/php/database.php @@ -33,7 +33,13 @@ function SQLite3_connect_try($filename, $mode, $trytoreconnect) if($trytoreconnect) { sleep(3); - $db = SQLite3_connect_try($filename, $mode, false); + return SQLite3_connect_try($filename, $mode, false); + } + else + { + // If we should not try again (or are already trying again!), we return the exception string + // so the user gets it on the dashboard + return $filename.": ".$exception->getMessage(); } } } @@ -48,9 +54,9 @@ function SQLite3_connect($filename, $mode=SQLITE3_OPEN_READONLY) { die("No database available"); } - if(!$db) + if(is_string($db)) { - die("Error connecting to database"); + die("Error connecting to database\n".$db); } // Add busy timeout so methods don't fail immediately when, e.g., FTL is currently reading from the DB