diff options
author | Jonas Kohl | 2024-09-17 14:51:23 +0200 |
---|---|---|
committer | Jonas Kohl | 2024-09-17 14:51:23 +0200 |
commit | a65d424263adfbff9629c7d91a613e4504c84613 (patch) | |
tree | 7d89c6d85168427782ae8c24625db14df90e376a /src/application/mystic | |
parent | f6dd78734f86f8daed7c5d472e7a199301095ff8 (diff) |
Add search
Diffstat (limited to 'src/application/mystic')
-rw-r--r-- | src/application/mystic/forum/Database.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/application/mystic/forum/Database.php b/src/application/mystic/forum/Database.php index a1e67ea..8ebc36b 100644 --- a/src/application/mystic/forum/Database.php +++ b/src/application/mystic/forum/Database.php @@ -414,6 +414,33 @@ class Database { return $items; } + public function execCustomQuery(string $query, ?array $customQueryParams = null, ?string $entityClassName = null): array { + if ($customQueryParams === null) + $result = \pg_query($this->connection, $query); + else + $result = \pg_query_params($this->connection, $query, $customQueryParams); + if ($result === false) + throw new \RuntimeException("Query failed: " . \pg_last_error($this->connection)); + $cols = null; + if ($entityClassName !== null) { + $reflClass = new ReflectionClass($entityClassName); + $cols = self::getColumns($reflClass); + } + $rowsOrItems = []; + while (($row = \pg_fetch_assoc($result)) !== false) { + if ($entityClassName !== null) { + $entity = new $entityClassName(); + foreach ($cols as $colName => $colProps) + self::assignValue($entity, $colProps, $row[$colName]); + $rowsOrItems []= $entity; + } else { + $rowsOrItems []= $row; + } + } + \pg_free_result($result); + return $rowsOrItems; + } + public function delete(Entity &$entity): bool { $entityClassName = get_class($entity); $tableName = self::getTableName($entityClassName); |