Skip to content

Commit f99ae09

Browse files
committed
fix sql search
1 parent ba78dbe commit f99ae09

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

resources/lib/UnitySQL.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ private function execute($statement)
5050

5151
private function search($table, $filters)
5252
{
53-
$stmt = $this->conn->prepare(
54-
"SELECT * FROM $table WHERE " .
55-
implode(" and ", array_map(fn($x) => "$x=:$x", array_keys($filters)))
56-
);
57-
foreach ($filters as $key => $val) {
58-
$stmt->bindValue(":$key", $val);
53+
if (count($filters) > 0) {
54+
$stmt = $this->conn->prepare(
55+
"SELECT * FROM $table WHERE " .
56+
implode(" and ", array_map(fn($x) => "$x=:$x", array_keys($filters)))
57+
);
58+
foreach ($filters as $key => $val) {
59+
$stmt->bindValue(":$key", $val);
60+
}
61+
} else {
62+
$stmt = $this->conn->prepare("SELECT * FROM $table");
5963
}
6064
$this->execute($stmt);
6165
return $stmt->fetchAll();

0 commit comments

Comments
 (0)