Skip to content

Commit 43b2118

Browse files
authored
Merge pull request #136 from UnityHPC/simonLeary42-patch-1
site var not found is an error
2 parents 735ca88 + 773b700 commit 43b2118

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

resources/lib/UnitySQL.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace UnityWebPortal\lib;
44

5+
use Exception;
56
use PDO;
67

78
class UnitySQL
@@ -278,8 +279,14 @@ public function getSiteVar($name)
278279
$stmt->bindParam(":name", $name);
279280

280281
$stmt->execute();
281-
282-
return $stmt->fetchAll()[0]['value'];
282+
$result = $stmt->fetchAll();
283+
if (empty($result)) {
284+
throw new Exception("Site variable with name '$name' not found.");
285+
}
286+
if (count($result) > 1) {
287+
throw new Exception("Multiple site variables found with name '$name'. Expected only one.");
288+
}
289+
return $result[0]['value'];
283290
}
284291

285292
public function updateSiteVar($name, $value)

0 commit comments

Comments
 (0)