Skip to content

site var not found is an error #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions resources/lib/UnitySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace UnityWebPortal\lib;

use Exception;
use PDO;

class UnitySQL
Expand Down Expand Up @@ -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)
Expand Down
Loading