Laravel: 错误 [PDOException]: 在 PostgreSQL 中找不到驱动程序

103

我正在尝试通过Laravel连接PostgreSQL数据库以执行php artisan migrate,但似乎没有成功,因为它正在读取MySQL的数据库名称。

这是来自database.php的命令:

'connections' => array(

    'sqlite' => array(
        'driver'   => 'sqlite',
        'database' => __DIR__.'/../database/production.sqlite',
        'prefix'   => '',
    ),

    'mysql' => array(
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'database',
        'username'  => 'root',
        'password'  => '',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),

    'pgsql' => array(
        'driver'   => 'pgsql',
        'host'     => 'localhost',
        'database' => 'postgres',
        'username' => 'postgres',
        'password' => 'root',
        'charset'  => 'utf8',
        'prefix'   => '',
        'schema'   => 'public',
    ),

    'sqlsrv' => array(
        'driver'   => 'sqlsrv',
        'host'     => 'localhost',
        'database' => 'database',
        'username' => 'root',
        'password' => '',
        'prefix'   => '',
    ),

),
如果我删除MySQL路径,将会得到:
[InvalidArgumentException]
Database [mysql] not configured.
当尝试运行'php artisan migrate'时,我遇到了'PDOException: could not find driver'的问题。我正在使用WAMP并且在Win8.1上。使用PostgreSQL作为数据库。
已经尝试了一系列的替代方案,但我仍然需要解决这个问题。在Apache、WAMP(从php文件夹中)和PostgreSQL中检查了php.ini文件。extension_dir是正确的,就像这样-> extension_dir = "c:/wamp/bin/php/php5.5.12/ext/"
extension=pdo_pgsql.dll和extension=pgsql.dll都被取消注释。
在“系统变量”中进行了路径设置的修改并重新启动电脑,但没有改善。
感谢到目前为止提供的帮助。
这是我的驱动程序php_pdo_driver.h和php_pdo.h,位于C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\php\SDK\include\ext\pdo目录下。
来自phpinfo的信息:
PHP版本5.5.12
编译器MSVC11(Visual C++ 2012)
Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:\php-sdk\oracle\x64\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\x64\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\x64\instantclient11\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--disable-static-analyze" "--with-pgo"

如果“database”是您的数据库名称,则您正在使用保留字作为数据库名称。 - David Jones
1
我的PostgreSQL数据库名称是postgres,正如代码中所示。 - Hyperion
太棒了,我完全误读了你的帖子。你确定Laravel默认尝试连接到你的Postgres数据库吗? - David Jones
我不这样认为 :( 它似乎默认尝试连接到MySQL,而我想找出如何连接到它。猜测用户 sgt 已经弄清楚了。非常感谢,我的朋友。 - Hyperion
22个回答

-2

这对我有用:

$ sudo apt-get -y install php5.6-pgsql
$ sudo service apache2 restart

我正在使用32位的Ubuntu 14进行工作


-4

使用 Laravel V 5.5.39 和 Php 7.1.12 是正常工作的,但是后来(更新的)php版本会导致问题。因此,更改Php版本,您将获得100%的解决方案。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接