Php 将postgres与laravel连接起来

Php 将postgres与laravel连接起来,php,postgresql,laravel,laravel-5,laravel-5.4,Php,Postgresql,Laravel,Laravel 5,Laravel 5.4,您好,我正在尝试将laravel 5.4与postgres连接,在更新数据库配置文件并运行php artisan migrate后,出现以下错误: [Illuminate\Database\QueryException] could not find driver (SQL: select * from information_schema.tables where t able_schema = public and table_name = migrations) [PDOExcepti

您好,我正在尝试将laravel 5.4与postgres连接,在更新数据库配置文件并运行
php artisan migrate
后,出现以下错误:

[Illuminate\Database\QueryException]
 could not find driver (SQL: select * from information_schema.tables where t
 able_schema = public and table_name = migrations)
[PDOException]
 could not find driver
这是我的
.env
文件

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=Portail
DB_USERNAME=php
DB_PASSWORD=php
'default' => env('DB_CONNECTION', 'pgsql'),
 'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'Portail'),
            'username' => env('DB_USERNAME', 'php'),
            'password' => env('DB_PASSWORD', 'php'),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
            'sslmode' => 'prefer', ], 
这是我的
database.php
文件

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=Portail
DB_USERNAME=php
DB_PASSWORD=php
'default' => env('DB_CONNECTION', 'pgsql'),
 'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'Portail'),
            'username' => env('DB_USERNAME', 'php'),
            'password' => env('DB_PASSWORD', 'php'),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
            'sslmode' => 'prefer', ], 

我通常使用phpPgAdmin

sudo-apt-get-install-php-pgsql。这是在linux中安装php pgsql驱动程序的命令

我发现解决方案有两个php.ini文件

  • C:\wamp64\bin\apache\apache2.4.9\bin

  • C:\wamp64\bin\php\php7.0.10

我必须在这两个文件中执行未注释的php_pdo_pgsql.dll和php_pgsql.dll
感谢您的帮助,我在使用php7.4的Ubuntu18.04上遇到了类似的问题 解决方案:

  • 首先用
    PHP-v
    检查您的PHP版本,在我的情况下,版本是php7.4,因此安装了必要的驱动程序,并安装了
    apt get install php7.4-pgsql

  • 最后重新启动PHP服务器


尝试将DB_HOST=localhost而不是127.0.0.1设置为不起作用,因为您可能没有安装PHP模块pgsql。我通常使用phpPgAdmin与PHP_pgsqli一起使用wampserver 3.0.6 64位和phpP7i使用windows和我的PHP_pgsql work我将PHP与phpPgAdmin连接,但不使用laravel