summaryrefslogtreecommitdiff
path: root/src/application/mystic/forum
diff options
context:
space:
mode:
Diffstat (limited to 'src/application/mystic/forum')
-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);