Laravel: 错误 [PDOException]: 在 PostgreSQL 中找不到驱动程序
P粉722409996
P粉722409996 2023-07-31 18:16:43
0
2
531

Translate: "我正在尝试通过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.



Translate: "编辑:当尝试执行 php artisan migrate 命令时,我遇到了 'PDOException: could not find driver' 错误。我正在使用 WAMP 并且在 Windows 8.1 上。数据库使用的是 PostgreSQL。"




EDIT: Translate: "我已经尝试了一系列的替代解决方案,但问题仍未解决。已经检查了 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 已经被取消注释。

已经在 '系统变量' 中进行了 PATH 的设置,并重新启动了计算机。但是仍然没有成功。

感谢迄今为止的帮助。

这是我的驱动程序 php_pdo_driver.h 和 php_pdo.h 位于 C:Program Files (x86)PostgreSQLEnterpriseDB-ApachePHPphpSDKincludeextpdo

从 phpinfo 中获取的信息:


Translate: "PHP 版本 5.5.12

编译器 MSVC11 (Visual C++ 2012) 配置命令 cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:php-sdkoraclex64instantclient10sdk,shared" "--with-oci8=C:php-sdkoraclex64instantclient10sdk,shared" "--with-oci8-11g=C:php-sdkoraclex64instantclient11sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--disable-static-analyze" "--with-pgo""



P粉722409996
P粉722409996

全部回复 (2)
P粉043295337

"对于 PDOException: could not find driver for MySQL 错误,如果是基于 Debian 的操作系统

sudo apt-get -y install php5-mysql
    P粉037450467

    Translate: "Be sure to configure the 'default' key in app/config/database.php.

    对于PostgreSQL,配置应该是 'default' => 'postgres'。

    如果您收到 [PDOException] could not find driver 错误,请检查您是否安装了正确的PHP扩展。您需要安装并启用 pdo_pgsql.so 和 pgsql.so。如何安装这些扩展因操作系统而异。

    对于Windows,pgsql扩展应该已经随官方PHP发行版预先下载。只需编辑您的php.ini文件,并取消注释以下行 extension=pdo_pgsql.so 和 extension=pgsql.so。

    此外,在php.ini中,确保 extension_dir 设置为正确的目录。它应该是您的PHP安装目录中名为extensions或ext或类似的文件夹。

    最后,将 libpq.dll 从 C:\wamp\bin\php\php5.*\ 复制到 C:\wamp\bin\apache*\bin,并通过WampServer界面重新启动所有服务。

    如果仍然出现异常,您可能需要将PostgreSQL的 \bin 目录添加到您的PATH环境变量中。"

    1. System Properties -> Advanced tab -> Environment Variables
    2. 在窗口的下半部分的 '系统变量' 组中,滚动查找并找到 PATH 条目。
    3. 选择它并点击编辑。
    4. 在现有条目的末尾,输入您的 postgres bin 目录的完整路径。bin 文件夹应该位于您的 postgres 安装目录的根目录中。
    5. 重新启动任何打开的命令提示符,或者为了确保,请重新启动您的计算机。

    这样应该可以解决任何问题。更多信息请参见:

      最新下载
      更多>
      网站特效
      网站源码
      网站素材
      前端模板
      关于我们 免责声明 Sitemap
      PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!