From 81b15d641cf8a859652fda08d7f6a18391978990 Mon Sep 17 00:00:00 2001 From: fuzzykitten Date: Thu, 5 Jun 2025 13:22:27 -0400 Subject: [PATCH] added error handling for search --- opt/search.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/opt/search.php b/opt/search.php index 69cbbd1..d677aee 100644 --- a/opt/search.php +++ b/opt/search.php @@ -64,7 +64,8 @@ function fulltext_search($db, $settings, $text) } $text = implode(' ', $new_text); - + $results = array(); + $db->exec('DROP TABLE search'); $db->exec('CREATE VIRTUAL TABLE IF NOT EXISTS search @@ -74,17 +75,24 @@ function fulltext_search($db, $settings, $text) SELECT sub, text, name, post_id, org_id, shadow FROM threads'); - $statement = $db->prepare("SELECT DISTINCT sub, text, name, post_id, org_id - FROM search - WHERE text MATCH ? - AND shadow = 'no' - ORDER BY rank"); - - $statement->bindParam(1, $text); - $result = $statement->execute(); - - $results = array(); - + try { + $db->enableExceptions(true); + $statement = $db->prepare("SELECT DISTINCT sub, text, name, + post_id, org_id + FROM search + WHERE text MATCH ? + AND shadow = 'no' + ORDER BY rank"); + + $statement->bindParam(1, $text); + $result = $statement->execute(); + } catch (Exception $fault) { + echo "The search: \"$text\" produced an error: " + . $fault->getMessage() + . "
Please go back to try again."; + quit($db, ''); + } + while ($row = $result->fetchArray(SQLITE3_NUM)) { $search = array(); $search['0'] = "{$row[0]}";