I have an issue connecting to my local PostgreSQL database. I'm using Docker to launch my project, all of this via WSL (Ubuntu) on Windows. PostgreSQL is installed on my WSL. Here's the Dockerfile:
ARG PHP_VERSION=""
FROM php:${PHP_VERSION:+${PHP_VERSION}-}fpm-alpine
RUN apk update; \
apk upgrade ;
RUN docker-php-ext-install \
pdo \
pdo_mysql \
mysql \
mysqli \
pgsql \
pdo_pgsql
RUN apk add \
--no-cache \
freetype \
libpng \
libjpeg-turbo \
freetype-dev \
libpng-dev \
libjpeg-turbo-dev \
libmcrypt-dev \
&& docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ \
&& NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
&& docker-php-ext-install -j${NPROC} gd \
&& apk del \
--no-cache \
freetype-dev \
libpng-dev \
libjpeg-turbo-dev \
&& docker-php-ext-install mcrypt
The environment variables for the connection are correct. Here is the PHP code for the connection :
try {
$dsn = "pgsql:host=" . getEnv('ROY_POSTGRESQL_ADDON_HOST') . ";port=" . getEnv("ROY_POSTGRESQL_ADDON_PORT") . ";dbname=" . getEnv("ROY_POSTGRESQL_ADDON_DB");
$this->pgsqlCon = new PDO($dsn, getEnv("ROY_POSTGRESQL_ADDON_USER"), getEnv("ROY_POSTGRESQL_ADDON_PASSWORD"));
} catch (\PDOException $e) {
echo ("Connection to the pgsql database failed " . $e->getMessage());
}
The environment variables for the connection are correct.
When I try to instantiate a Writer object in which is the piece of PHP code, the error message is as follows:
Connection to the pgsql database failed : "could not find driver."