我是Docker的新手,但我遇到了麻烦,我总是得到这个错误:
Fatal error: Uncaught PDOException: could not find driver in /var/www/html/index.php:16 Stack trace: #0 /var/www/html/index.php(16): PDO->__construct('pgsql:host=loca...', 'project', 'project') #1 {main} thrown in /var/www/html/index.php on line 16
这是我的index.php:
<?php
$database = $user = $password = "project";
$host = "localhost";
$connection = new PDO("pgsql:host={$host};dbname={$database};charset=utf8", $user, $password);
$query = $connection->query("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_TYPE='BASE TABLE'");
$tables = $query->fetchAll(PDO::FETCH_COLUMN);
这就是我的Dockerfile的样子:
FROM php:7.0-fpm
RUN apt-get update && apt-get install -y
RUN apt-get install git
RUN docker-php-ext-install mbstring mcrypt opcache
RUN docker-php-ext-configure pgsql -with-pgsql=/usr/include/postgresql/
RUN docker-php-ext-install pgsql pdo_pgsql
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
但是我觉得Dockerfile没有运行,当我运行docker-compose up -d
命令时它太快了。
有人知道我为什么会得到PDOException?
答案 0 :(得分:0)
如果已安装软件包,则需要在php.ini中启用该模块
将以下行添加到php.ini文件
extension=php_pgsql.so