Laravel:错误 [PDOException]:无法在 PostgreSQL 中找到驱动程序 [英] Laravel: Error [PDOException]: Could not Find Driver in PostgreSQL

查看:36
本文介绍了Laravel:错误 [PDOException]:无法在 PostgreSQL 中找到驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 Laravel 连接 PostgreSQL 数据库以进行 php artisan 迁移,但似乎没有被引导,因为它正在读取 MySQL 的数据库名称.

这是来自database.php的命令:

'connections' =>大批('sqlite' =>大批('司机' =>'sqlite','数据库' =>__DIR__.'/../database/production.sqlite','前缀' =>'',),'mysql' =>大批('司机' =>'mysql','主机' =>'本地主机','数据库' =>'数据库','用户名' =>'根','密码' =>'','字符集' =>'utf8','整理' =>'utf8_unicode_ci','前缀' =>'',),'pgsql' =>大批('司机' =>'pgsql','主机' =>'本地主机','数据库' =>'postgres','用户名' =>'postgres','密码' =>'根','字符集' =>'utf8','前缀' =>'','架构' =>'民众',),'sqlsrv' =>大批('司机' =>'sqlsrv','主机' =>'本地主机','数据库' =>'数据库','用户名' =>'根','密码' =>'','前缀' =>'',),),

如果我删除 MySQL 路径,我会得到:

[InvalidArgumentException]数据库 [mysql] 未配置.

<小时>尝试执行 php artisan migrate 时,我收到PDOException:找不到驱动程序".我正在使用 WAMP 并且我在 Win8.1 中.使用 PostgreSQL 作为数据库.

<小时>已经尝试了一系列替代解决方案,但我仍然应该解决这个问题.php.ini 文件已在 Apache、WAMP(来自 php 文件夹)和 PostgreSQL 中检查.extension_dir 是正确的 -> extension_dir = "c:/wamp/bin/php/php5.5.12/ext/"

extension=pdo_pgsql.dllextension=pgsql.dll 没有注释.

在系统变量"中完成PATH 技巧并重新启动.没有机会.

感谢到目前为止的帮助.

这些是我的驱动程序 php_pdo_driver.h &php_pdo.h 来自 C:Program Files (x86)PostgreSQLEnterpriseDB-ApachePHPphpSDKincludeextpdo

来自phpinfo的信息:

<块引用>

PHP 5.5.12 版

编译器 MSVC11 (Visual C++ 2012) 配置命令 cscript/nologoconfigure.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"

解决方案

一定要在app/config/database.php中配置'default'键>

对于 postgres,这将是 'default' =>'postgres',

如果您收到 [PDOException] 找不到驱动程序 错误,请检查您是否安装了正确的 PHP 扩展.您需要安装并启用 pdo_pgsql.sopgsql.so.有关如何执行此操作的说明因操作系统而异.

对于 Windows,pgsql 扩展应该与官方 PHP 发行版一起预先下载.只需编辑您的 php.ini 并取消注释 extension=pdo_pgsql.soextension=pgsql.so

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

最后,将libpq.dllC:wampinphpphp5.*复制到C:wampinapache*in 并通过 WampServer 接口重启所有服务.

如果仍然出现异常,您可能需要将 postgres in 目录添加到您的 PATH 中:

  1. 系统属性 -> 高级选项卡 -> 环境变量
  2. 在窗口下半部分的系统变量"组中,滚动并找到 PATH 条目.
  3. 选择它并点击编辑
  4. 在现有条目的末尾,输入 postgres bin 目录的完整路径.bin 文件夹应位于 postgres 安装目录的根目录中.
  5. 重新启动所有打开的命令提示符,或者确定重新启动您的计算机.

这有望解决任何问题.有关更多信息,请参阅:

I'm trying to connect with PostgreSQL database through Laravel in order to do a php artisan migrate but doesn't seem to be directed since it's reading the database name of MySQL.

Here are the commands from 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'   => '',
    ),

),

If I remove the MySQL paths I'll get:

[InvalidArgumentException]
Database [mysql] not configured.


EDIT: When trying to do php artisan migrate I get a 'PDOException: could not find driver'. I'm using WAMP and I'm in Win8.1. Using PostgreSQL as database.


EDIT: Have experimented a series of alternative solutions but I'm still ought to get this solved. The php.ini file was checked in Apache, WAMP (from php folder) and PostgreSQL. The extension_dir is correct as it being -> extension_dir = "c:/wamp/bin/php/php5.5.12/ext/"

The extension=pdo_pgsql.dll and extension=pgsql.dll are uncommented.

Done the PATH trick in the 'System Variables' and rebooted. No chance.

Thanks for the help so far.

These are my drivers php_pdo_driver.h & php_pdo.h from C:Program Files (x86)PostgreSQLEnterpriseDB-ApachePHPphpSDKincludeextpdo

Information from phpinfo:

PHP Version 5.5.12

Compiler 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-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"

解决方案

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

For postgres, this would be 'default' => 'postgres',

If you are receiving a [PDOException] could not find driver error, check to see if you have the correct PHP extensions installed. You need pdo_pgsql.so and pgsql.so installed and enabled. Instructions on how to do this vary between operating systems.

For Windows, the pgsql extensions should come pre-downloaded with the official PHP distribution. Just edit your php.ini and uncomment the lines extension=pdo_pgsql.so and extension=pgsql.so

Also, in php.ini, make sure extension_dir is set to the proper directory. It should be a folder called extensions or ext or similar inside your PHP install directory.

Finally, copy libpq.dll from C:wampinphpphp5.* into C:wampinapache*in and restart all services through the WampServer interface.

If you still get the exception, you may need to add the postgres in directory to your PATH:

  1. System Properties -> Advanced tab -> Environment Variables
  2. In 'System variables' group on lower half of window, scroll through and find the PATH entry.
  3. Select it and click Edit
  4. At the end of the existing entry, put the full path to your postgres bin directory. The bin folder should be located in the root of your postgres installation directory.
  5. Restart any open command prompts, or to be certain, restart your computer.

This should hopefully resolve any problems. For more information see:

这篇关于Laravel:错误 [PDOException]:无法在 PostgreSQL 中找到驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆