summaryrefslogtreecommitdiff
path: root/src/application/mystic/forum/Database.php
diff options
context:
space:
mode:
authorJonas Kohl2024-09-17 14:51:23 +0200
committerJonas Kohl2024-09-17 14:51:23 +0200
commita65d424263adfbff9629c7d91a613e4504c84613 (patch)
tree7d89c6d85168427782ae8c24625db14df90e376a /src/application/mystic/forum/Database.php
parentf6dd78734f86f8daed7c5d472e7a199301095ff8 (diff)
Add search
Diffstat (limited to 'src/application/mystic/forum/Database.php')
-rw-r--r--src/application/mystic/forum/Database.php27
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);