diff --git a/docker-compose.yaml b/docker-compose.yaml index d979527..d159f72 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -23,11 +23,13 @@ services: web: command: php -S 0.0.0.0:8080 - image: php:8-alpine + build: web/ volumes: - ./web/src:/src environment: - DOMAIN=${DOMAIN} + - DB_HOST=${DB_HOST} + - DB_NAME=${DB_NAME} working_dir: /src networks: - fedilove diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..b69f0cc --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,5 @@ +FROM php:8-alpine + +RUN apk add autoconf gcc libc-dev make --update +RUN pecl install mongodb +RUN echo 'extension=mongodb.so' > /usr/local/etc/php/conf.d/docker-php-ext-mongodb.ini diff --git a/web/src/database.php b/web/src/database.php new file mode 100644 index 0000000..a955646 --- /dev/null +++ b/web/src/database.php @@ -0,0 +1,21 @@ +manager = new MongoDB\Driver\Manager("mongodb://$db_host:27017"); + $this->db_name = $db_name; + } + + function query($table, $q) { + $query = new MongoDB\Driver\Query($q); + $cursor = $manager->executeQuery($this->db_name.'.'.$table, $query); + return $cursor->toArray(); + } +}