diff --git a/resources/lib/UnitySQL.php b/resources/lib/UnitySQL.php index 8a82bb2..63d4c4c 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -2,6 +2,7 @@ namespace UnityWebPortal\lib; +use Exception; use PDO; class UnitySQL @@ -278,8 +279,14 @@ public function getSiteVar($name) $stmt->bindParam(":name", $name); $stmt->execute(); - - return $stmt->fetchAll()[0]['value']; + $result = $stmt->fetchAll(); + if (empty($result)) { + throw new Exception("Site variable with name '$name' not found."); + } + if (count($result) > 1) { + throw new Exception("Multiple site variables found with name '$name'. Expected only one."); + } + return $result[0]['value']; } public function updateSiteVar($name, $value)